iOS-确定网络状态 (3G, WiFi )
2016-08-25 本文已影响40人
亦晴工作室
AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
[manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusUnknown:
{
UIAlertController *ac = [UIAlertController alertControllerWithTitle:@"ESports" message:@"未识别的网络" preferredStyle:UIAlertControllerStyleAlert];
[ac addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
break;
}
case AFNetworkReachabilityStatusNotReachable:
{
UIAlertController *ac = [UIAlertController alertControllerWithTitle:@"ESports" message:@"未连接" preferredStyle:UIAlertControllerStyleAlert];
[ac addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
break;
}
case AFNetworkReachabilityStatusReachableViaWWAN:
{
UIAlertController *ac = [UIAlertController alertControllerWithTitle:@"ESports" message:@"您确定要使用移动网络?" preferredStyle:UIAlertControllerStyleAlert];
[ac addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
break;
}
case AFNetworkReachabilityStatusReachableViaWiFi:
{
UIAlertController *ac = [UIAlertController alertControllerWithTitle:@"ESports" message:@"WiFi环境" preferredStyle:UIAlertControllerStyleAlert];
[ac addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
break;
}
default:
break;
}
}];
// 开始监听
[manager startMonitoring];