在Iphone模拟器上使用可达性并且没有wifi
问题描述:
我在我的IOS应用程序中使用可达性来确定连接。在Iphone模拟器上使用可达性并且没有wifi
如果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
有谁知道我怎么能处理好与更好的错误连接的这种情况呢?
答
在appdelegate中创建以下方法以在任何类上使用它。
-(BOOL)isHostAvailable
{
//return NO; // force for offline testing
Reachability *hostReach = [Reachability reachabilityForInternetConnection];
NetworkStatus netStatus = [hostReach currentReachabilityStatus];
return !(netStatus == NotReachable);
}
谢谢,我仍然得到了执行上述相同的错误。 错误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