网络状态提醒
2017-06-21 本文已影响13人
Suger_森
导入AFNetworking.h
pragma mark -- 检查网络状态
- (void)checkNetworking{
// 1.创建对象
AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];// 2.检查网络
//设置网络状态发生改变触发的block
[manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus *status) {
/ *
AFNetworkReachabilityStatusUnknown = -1, 未知AFNetworkReachabilityStatusNotReachable = 0, 不可用
AFNetworkReachabilityStatusReachableViaWWAN = 1, 流量
AFNetworkReachabilityStatusReachableViaWiFi = 2, wifi
*/
NSArray *array = @[@"未知错误", @"无网络", @"使用流量", @"wifi环境"];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"网络状态检查” message:array[status + 1] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction
*action) {
[alert dismissViewControllerAnimated:YES completion:ni];
}];
[alert addAction:action];
[self presentViewController:alert animated:YES completion:nil];
}];
// 开始检查
[manager
startMonitoring];// [manager stopMonitoring];
}