在 AppDelegate.m 里面- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法下调用网络检测方法
#pragma mark-监听网络
- (void)isNetworking
{
// 开启网络指示器
[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusUnknown:
CLog(@"未识别的网络");
break;
case AFNetworkReachabilityStatusNotReachable:
{
CLog(@"无网络连接");
//跳转到“About”(关于本机)页面
[UIAlertView bk_showAlertViewWithTitle:@"无网络连接" message:@"请检查网络环境,并确认开启网络访问权限!" cancelButtonTitle:@"取消" otherButtonTitles:@[@"检查网络"] handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
if (buttonIndex == 1) {
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
}];
// NSURL *url = [NSURL URLWithString:@"prefs:root=General&path=Network"];
// if ([[UIApplication sharedApplication] canOpenURL:url])
// {
// [[UIApplication sharedApplication] openURL:url];
// }else{
// NSLog(@"can not open");
// }
}
break;
case AFNetworkReachabilityStatusReachableViaWiFi:
CLog(@"WIFI");
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
CLog(@"蜂窝移动");
break;
default:
break;
}
}];
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
}
打开系统蜂窝网络设置的方法不推荐,可能上架会被拒,而且iOS10下面无法打开
网友评论