//创建网络状态监测管理者
AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
//监听改变
[manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusUnknown:
NSLog(@"未知");
break;
case AFNetworkReachabilityStatusNotReachable:
NSLog(@"没有网络");
[MBProgressHUD showError:@"网络不可用,请连接网络"];
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
NSLog(@"3G|4G");
break;
case AFNetworkReachabilityStatusReachableViaWiFi:
NSLog(@"WiFi");
break;
default:
break;
}
}];
[manager startMonitoring];//开始监听
}
网友评论