在我的iPhone应用程序中,我需要检测互联网连接的可用性。
所以我引用了苹果公司的“可达性”项目中的一些文件。
链接如下:
http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html
我创建了一个新项目并在viewwill中实现了下面的代码,但是应用程序崩溃了。
我包括了苹果演示项目中的Reachability.h,Reachability.m。
我还包括系统配置框架。
当互联网运行时,应用程序运行良好。但当互联网不工作时,应用程序崩溃。
即使我检查了控制台,但控制台中没有显示任何通知或错误。
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];
}
坠机的原因是什么?
我该怎么办?
谢谢!!