我在我的项目中使用可达性,当我尝试获取有关连接类型的信息时,我收到了这个错误。
*** Assertion failure in -[Reachability currentReachabilityStatus],/myProjectPath/Reachability.m:530
2012-04-03 21:25:45.619 Traffic[7862:11603] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'currentNetworkStatus called with NULL reachabilityRef'
我不知道我的代码有什么问题。我在 ReachabilityAppDelegate 中放置了相同的代码来获取连接状态。
我的代码:
// get type of user connection
NSString* statusString= @"NA";
Reachability *curReach = [[Reachability alloc] init];
NetworkStatus netStatus = [curReach currentReachabilityStatus];
BOOL connectionRequired= [curReach connectionRequired];
switch (netStatus)
{
case NotReachable:
{
statusString = @"NA";
//Minor interface detail- connectionRequired may return yes, even when the host is unreachable. We cover that up here...
connectionRequired= NO;
break;
}
case ReachableViaWWAN:
{
statusString = @"WWAN";
break;
}
case ReachableViaWiFi:
{
statusString= @"WIFI";
break;
}
}