26>AFN現在のネットワークの状態を監視

1623 ワード

-(void)checkNetworking
{
    AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
    [mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
       //           ,    block
        switch (status) {
            case AFNetworkReachabilityStatusReachableViaWiFi:
                NSLog(@"   WIFI  ");
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                NSLog(@"       ");
                break;
            case AFNetworkReachabilityStatusNotReachable:
                NSLog(@"     ");
                break;
            case AFNetworkReachabilityStatusUnknown:
                NSLog(@"    ");
                break;
            default:
                break;
        }
    }];
    //       
    [mgr startMonitoring];
}