美文网首页IOSbug
记一笔 Reachability使用

记一笔 Reachability使用

作者: 司马捷 | 来源:发表于2015-06-18 14:48 被阅读265次

    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使用

      本文链接:https://www.haomeiwen.com/subject/hvesqttx.html