我在我的項目上使用可達性,當我試圖獲取有關連接類型的信息時,我得到此錯誤。連接狀態與可達性
*** 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;
}
}