本文介绍了可达性无法按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从Apple下载Reachability,使用此方法检查活动连接:
Downloaded Reachability from Apple, using this method to check for an active connection:
-(BOOL)isReachable{
Reachability *r = [Reachability reachabilityWithHostName:@"http://www.google.com"];
if(NotReachable == [r currentReachabilityStatus]) {
NSLog(@"Not Reachable");
return NO;
}
NSLog(@"Reachable");
return YES;
}
尽管已连接,但每次都返回NO?无法弄清楚为什么......
Returns NO every single time despite being connected? Can't figure out why...
任何想法?谢谢。
在附注中,有人可以推荐一个干净的Reachability单例类吗?
On a side note, can anyone recommend a good clean Reachability singleton class?
推荐答案
已编辑:您应从 reachabilityWithHostName $ c $中删除协议
http
c>调用,将其更新为
EDITED: you should remove the protocol, http
from your reachabilityWithHostName
call, so updated it to
Reachability *reachability = [Reachability reachabilityWithHostname:@"www.google.com"];
NetworkStatus netStatus = [reachability currentReachabilityStatus];
这篇关于可达性无法按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!