iOS监听网络状态(原生)

2016-07-12  本文已影响321人  952625a28d0d
Reachability *reachability = [Reachability reachabilityWithHostName:@"www.baidu.com"];
    NetworkStatus netStatus = [reachability currentReachabilityStatus];
    switch (netStatus) {
        case NotReachable:
            break;
        case ReachableViaWiFi:
            networkStatus = 
            break;
        case ReachableViaWWAN:
            break;
            
        default:
            break;
    }```

- 监听网络状态

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
[self.hostReachability startNotifier];


- 网络改变获取网络状态

上一篇 下一篇

猜你喜欢

热点阅读