//创建网络监听管理者对象
AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
//开始监听
[manager startMonitoring];
//监听回调
[manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusUnknown:
NSLog(@"未识别的网络");
break;
case AFNetworkReachabilityStatusNotReachable:
NSLog(@"不可达的网络(未连接)");
break;
case AFNetworkReachabilityStatusReachableViaWiFi:
NSLog(@"wifi的网络");
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
NSLog(@"2G,3G,4G...的网络");
break;
default:
break;
}
}];
ps:如果要在case中定义变量需要加花括号{}
网友评论