2011-08-23 60 views
1

我得到了我的可达性代码的误报。当网络可用但未激活时,我得到UIAlert“无互联网连接”。很感谢任何形式的帮助。可达性错误肯定

//Check for Internet 
Reachability* wifiReach = [[Reachability reachabilityWithHostName: @"www.apple.com"] retain]; 
NetworkStatus netStatus = [wifiReach currentReachabilityStatus]; 
switch (netStatus) 
{ 
    case NotReachable: 
    { 
     NSLog(@"Access Not Available"); 
     break; 
    } 

    case ReachableViaWWAN: 
    { 
     NSLog(@"Reachable WWAN"); 
     break; 
    } 
    case ReachableViaWiFi: 
    { 
     NSLog(@"Reachable WiFi"); 
     break; 
    } 
} 

if (netStatus==NotReachable){ 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Internet Required" message:@"There is no internet connection. Please connect and try again" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; 

}else{ 
    //Push Controller 
} 
+0

重复这个问题的 http://stackoverflow.com/questions/3086816/reachability-on-iphone-app-with-a-false-positive-will-it-get-past-apple – enbr

+0

不确切地说,你提到的问题的答案是仅仅不使用可达性。检查出:http://stackoverflow.com/questions/1281232/reachability-sometimes-fails-even-when-we-do-have-an-internet-connection更详细地解释 – iOSDevSF

+0

@ stevebay22是什么让你觉得那不是没有正确的答案吗? – hotpaw2

回答

1

与上一个问题相同的答案。

在您的应用程序或某个以前的应用程序尝试连接并等待数据后,可达性有时只会给出正确的答案。所以你可能只是试图从你的连接中获取数据,因为这可能比问可达性API更快地给你一个更正确的答案。也许只是让用户决定一个活动指标已经旋转了足够长的时间。

相关问题