2012-09-05 80 views
2

我在我的IOS應用程序中使用可達性來確定連接。在Iphone模擬器上使用可達性並且沒有wifi

這個職位wifi on iphone simulator

如果WiFi被關閉模擬器互聯網連接以下是不可用,但電話仍然是Wi-Fi連接,因此連接沒有改變。這一切都很好,理解,當然我可以在設備上進行測試。

但是,我正在尋找處理錯誤,用戶連接到無線網絡,但WiFi沒有像下面的屏幕截圖的互聯網連接。

我使用可達下列方式:

#pragma mark -() 
- (void)monitorReachability { 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:ReachabilityChangedNotification object:nil]; 

self.hostReach = [Reachability reachabilityWithHostname: @"api.parse.com"]; 
[self.hostReach startNotifier]; 

self.internetReach = [Reachability reachabilityForInternetConnection]; 
[self.internetReach startNotifier]; 

self.wifiReach = [Reachability reachabilityForLocalWiFi]; 
[self.wifiReach startNotifier]; 

}

//可達性,只要狀態發生變化時調用。 (void)reachabilityChanged:(NSNotification *)note { Reachability * curReach =(Reachability *)[note object]; NSParameterAssert([curReach isKindOfClass:[Reachability class]]); NSLog(@「Reachability changed:%@」,curReach); networkStatus = [curReach currentReachabilityStatus];

}

我使用可達弧從tonymillion的github上的位置:https://github.com/tonymillion/Reachability

有誰知道我怎麼能處理好與更好的錯誤連接的這種情況呢? enter image description here

回答

2

在appdelegate中創建以下方法以在任何類上使用它。

-(BOOL)isHostAvailable 
{ 
    //return NO; // force for offline testing 
    Reachability *hostReach = [Reachability reachabilityForInternetConnection]; 
    NetworkStatus netStatus = [hostReach currentReachabilityStatus]; 
    return !(netStatus == NotReachable); 
} 
+0

謝謝,我仍然得到了執行上述相同的錯誤。 錯誤20606:1b03]錯誤:錯誤域= NSURLErrorDomain代碼= -1009「Internet連接似乎處於脫機狀態。」 UserInfo = 0xc3748e0 {NSErrorFailingURLStringKey = https://api.parse.com/2/user_login,NSErrorFailingURLKey = https://api.parse.com/2/user_login,NSLocalizedDescription =互聯網連接似乎處於脫機狀態,NSUnderlyingError = 0xe0962c0 「Internet連接似乎處於脫機狀態。」}(代碼:100,版本:1.1.0) – StuartM

相關問題