1

我在我的项目中使用可达性,当我尝试获取有关连接类型的信息时,我收到了这个错误。

*** 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;
    }
}
4

2 回答 2

1

我有同样的问题。我if reachability.currentReachabilityStatus() == NotReachable在做之前正在检查

reachability = Reachability.forInternetConnection()
reachability.startNotifier()

问题是您在启动通知程序之前询问状态,并且_reachabilityRef是零。

确保按照他们需要的顺序拨打电话。首先启动通知程序,然后仅在检查/询问状态之后。

于 2017-01-23T14:06:40.263 回答
0

检查:

//Called by Reachability whenever status changes.
- (void) reachabilityChanged: (NSNotification* )note
{
    Reachability* curReach = [note object];
    NSParameterAssert([curReach isKindOfClass: [Reachability class]]);
    [self updateInterfaceWithReachability: curReach];
}

在应用程序委托中。NSParameterAssert 在我的情况下导致崩溃

于 2012-07-19T08:57:50.700 回答