检查联网状态

用AFNetWork监控联网状态   


    AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
    // 当网络状态改变了,就会调用
    [mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusUnknown: // 未知网络
            case AFNetworkReachabilityStatusNotReachable: // 没有网络(断网)
                HMLog(@"没有网络(断网)");
                [MBProgressHUD showError:@"网络异常,请检查网络设置!"];
                break;
                
            case AFNetworkReachabilityStatusReachableViaWWAN: // 手机自带网络
                HMLog(@"手机自带网络");
                break;
                
            case AFNetworkReachabilityStatusReachableViaWiFi: // WIFI
                HMLog(@"WIFI");
                break;
        }
    }];
    // 开始监控
    [mgr startMonitoring];




你可能感兴趣的:(检查联网状态)