在我的 iPhone 应用程序中,我需要检测互联网连接的可用性。
所以我引用了 Apple 的“Reachability”项目中的一些文件。
链接如下:
http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html
我创建了一个新项目并在 viewWillAppear 中实现了以下代码,但应用程序崩溃了。
我包含了来自 Apple 演示项目的 Reachability.h、Reachability.m。
我还包括了 SystemConfiguration 框架。
互联网工作时,应用程序工作正常。但是当互联网不工作时应用程序崩溃。
即使我检查了控制台,但控制台中没有显示任何通知或错误。
Reachability *r = [Reachability reachabilityWithHostName:@"www.google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
if ((internetStatus == ReachableViaWiFi) || (internetStatus == ReachableViaWWAN))
{
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"Internet Connection" message:@"Available" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[myAlert show];
[myAlert release];
}
else
{
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection" message:@"This app require an internet connection via WiFi or cellular network to work." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[myAlert show];
[myAlert release];
}
崩溃的原因可能是什么?
我该怎么办?
谢谢!!