//利用AFN测试网络连接
// MARK: 网络检测
AFNetworkReachabilityManager*manager = [AFNetworkReachabilityManagersharedManager];
[managerstartMonitoring];
[managersetReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatusstatus) {
/**
AFNetworkReachabilityStatusUnknown= -1,
AFNetworkReachabilityStatusNotReachable= 0,
AFNetworkReachabilityStatusReachableViaWWAN= 1,
AFNetworkReachabilityStatusReachableViaWiFi= 2,
**/
switch(status) {
case -1:
break;
case AFNetworkReachabilityStatusNotReachable:
//无法连接
NSLog(@"无法连接");
//添加遮罩警示信息
[SVProgressHUDsetMinimumDismissTimeInterval:1];
[SVProgressHUDshowErrorWithStatus:@"网络连接失败"];
[SVProgressHUDsetDefaultMaskType:SVProgressHUDMaskTypeBlack];
break;
case1:
//通过WWAN连接
break;
case2:
//通过WIFI连接
break;
default:
break;
}
}];
网友评论