在iOS 7 iphone 5中使用错误的状态代码响应可达性 [英] Reachability responding with wrong status code in iOS 7 iphone 5
问题描述
我在使用iOS 7的iPhone 5上遇到了奇怪的问题,我已经测试过与其他设备相同的代码,如iPad1,2,3和iPhone 4,4s等,包括iOS 7在内的不同iOS组合。
I am facing weird problem on iPhone 5 with iOS 7, i have tested same code with other devices like iPad1, 2, 3 and iPhone 4, 4s etc. with different iOS combination including iOS 7.
问题:
当我打开飞机模式时,我会按预期获得状态<$的可达性通知c $ c> NotReachable 但是该应用程序收到状态代码 ReachableViaWWAN
的通知后不会发生这种情况。
When i turn on airplane mode i do get reachability notification as expected with status NotReachable
but immediately after that app receives notification with status code ReachableViaWWAN
which is not expected.
代码:
+(BOOL)checkReachability
{
Reachability* internetReachable = [Reachability reachabilityForInternetConnection];
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch (internetStatus)
{
case NotReachable:
{
DebugLog(@"The internet is down.");
return NO;
break;
}
default:
return YES;
break;
}
return YES;
}
我在切换之前添加了日志,返回状态为飞机模式中的ReachableViaWWAN
..
I added log before switch which is returning status as ReachableViaWWAN
in airplane mode..
可能的解决方法可能是:
为 ReachableViaWWAN
添加案例,并在这种情况下检查主机是否可达。并相应地返回BOOL值。
Add case for ReachableViaWWAN
and check host reachable in that case. And return BOOL value accordingly.
任何人遇到类似的问题?我搜索过但没有找到类似的情况。
Anyone faced similar problem ?? i have searched but haven't found similar scenario.
提前致谢!!
推荐答案
我遇到了同样的问题。解决方案是检查标志 isConnectionRequired 。文档说:
I had the same problem. The solution is to check the flag isConnectionRequired. The documentation says:
WWAN可能可用,但在建立连接之前不会处于活动状态。
WWAN may be available, but not active until a connection has been established.
代码
Code
BOOL isServerAvailable;
Reachability *reachability = [Reachability reachabilityForInternetConnection];
if ((reachability.isConnectionRequired) || (NotReachable == reachability.currentReachabilityStatus)) {
isServerAvailable = NO;
} else if((ReachableViaWiFi == reachability.currentReachabilityStatus) || (ReachableViaWWAN == reachability.currentReachabilityStatus)){
isServerAvailable = YES;
}
这篇关于在iOS 7 iphone 5中使用错误的状态代码响应可达性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!