【发布时间】:2011-10-18 18:42:57
【问题描述】:
我正在使用此代码检查互联网连接,但我遇到了一个崩溃提示 +[Reachability reachabilityForInternetConnection]: unrecognized selector sent to class 0xcbe0c8
我已导入 Reachability .h/.m 和 systemconfig 框架。崩溃发生在self.internetRechable = [[Reachability reachabilityForInternetConnection] retain];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil];
self.internetRechable = [[Reachability reachabilityForInternetConnection] retain];
[self.internetRechable startNotifier];
// check if a pathway to a random host exists
self.hostReachable = [[Reachability reachabilityWithHostName: @"www.apple.com"] retain];
[self.hostReachable startNotifier];
- (void) checkNetworkStatus:(NSNotification *)notice
{
// called after network status changes
NetworkStatus internetStatus = [self.internetRechable currentReachabilityStatus];
switch (internetStatus)
{
case NotReachable:
{
NSLog(@"The internet is down.");
// self.internetActive = NO;
break;
}
case ReachableViaWiFi:
{
NSLog(@"The internet is working via WIFI.");
// self.internetActive = YES;
break;
}
case ReachableViaWWAN:
{
NSLog(@"The internet is working via WWAN.");
// self.internetActive = YES;
break;
}
}
NetworkStatus hostStatus = [self.hostReachable currentReachabilityStatus];
switch (hostStatus)
{
case NotReachable:
{
NSLog(@"A gateway to the host server is down.");
// self.hostActive = NO;
break;
}
case ReachableViaWiFi:
{
NSLog(@"A gateway to the host server is working via WIFI.");
// self.hostActive = YES;
break;
}
case ReachableViaWWAN:
{
NSLog(@"A gateway to the host server is working via WWAN.");
// self.hostActive = YES;
break;
}
}
}
【问题讨论】:
-
不,我已经完成了
@class Reachability并且我也已经导入了 -
是的,我已经导入了文件,我已经完成了
#import "Reachability.h"等 -
我做到了,它在
Reachability *newReach = [Reachability reachabilityForInternetConnection];崩溃了 -
从 Reachability 2.0 升级到 2.2 后,我现在收到此错误:` *** 由于未捕获的异常 'NSInvalidArgumentException' 导致应用程序终止,原因:'+[Reachability reachabilityForInternetConnection]:无法识别的选择器发送到类 0xcbf0c4'`
-
另外两个问题是在黑暗中拍摄的。 1)您的源文件是否已从原始苹果文件损坏/更改? 2) 如果您在 xCode 中使用工作区,有时文件将在工作区中,但不在项目中。当您折叠项目披露三角形时,它的文件将折叠掉。是这样吗?
标签: iphone objective-c cocoa-touch crash reachability