ネットワーク状態の確認

899 ワード

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];

使用する