美文网首页
iOS-确定网络状态 (3G, WiFi )

iOS-确定网络状态 (3G, WiFi )

作者: 亦晴工作室 | 来源:发表于2016-08-25 11:11 被阅读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];
    

    相关文章

      网友评论

          本文标题:iOS-确定网络状态 (3G, WiFi )

          本文链接:https://www.haomeiwen.com/subject/jolosttx.html