2011-08-23 73 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更快地給你一個更正確的答案。也許只是讓用戶決定一個活動指標已經旋轉了足夠長的時間。

相關問題