AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
[mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
// 当网络状态发生改变的时候调用这个block
switch (status) {
case AFNetworkReachabilityStatusReachableViaWiFi:
NSLog(@"WIFI");
WeakSelf.statusInternet = @"WIFI";
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
NSLog(@"自带网络");
WeakSelf.statusInternet = @"4G";
break;
case AFNetworkReachabilityStatusNotReachable:
NSLog(@"没有网络");
WeakSelf.statusInternet = @"NOInternet";
break;
case AFNetworkReachabilityStatusUnknown:
NSLog(@"未知网络");
WeakSelf.statusInternet = @"NOWIFI";
break;
default:
break;
}
}];
// 开始监控
[mgr startMonitoring];
网友评论