AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
[manager startMonitoring];
[manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { switch (status) { case AFNetworkReachabilityStatusUnknown: NSLog(@"未识别的网络"); break; case AFNetworkReachabilityStatusNotReachable:{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Prompt" メッセージ:@"現在のネットワークを利用できません。ネットワーク設定を確認してください" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler: nil ];
[アラート addAction:アクション];
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alert animation:YES 完了:nil];
}
ブレーク;
case AFNetworkReachabilityStatusReachableViaWWAN:
NSLog(@"2G,3G,4G...的网络");
壊す;
case AFNetworkReachabilityStatusReachableViaWiFi:
NSLog(@"wifi的网络");
壊す;
デフォルト:
ブレーク;
}
}];
AFNetworking はネットワークの状態を監視します
おすすめ
転載: blog.csdn.net/ForeverMyheart/article/details/79817674#comments_19736422
おすすめ
ランキング