记一笔 Reachability使用

1.第一次测试代码

-(void)startNetWorkNotify{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:)name:kReachabilityChangedNotification object:nil];
_reachablity = [Reachability reachabilityForInternetConnection];
[_reachablity startNotifier];
}

-(void)reachabilityChanged:(NSNotification *)notify{
Reachability *reach = [notify object];
if([reach isKindOfClass:[Reachability class]]){
NetworkStatus status = [reach currentReachabilityStatus]; LOG(@"------------检测到网络--> %ld",(long)status);
if (status == 1) {
[reach stopNotifier];
[self autoStartRetryConnect];
}
}
}

死活没有反应,reachabilityChanged 方法一直接受不到消息.

实在没办法,道网上重新下载了最新的Reachability ,经测试 果然好用. 断开感知延迟1秒,连接很快.

https://developer.apple.com/library/ios/samplecode/Reachability/Reachability.zip 资源地址以供下载

你可能感兴趣的:(记一笔 Reachability使用)