AFNetworking 判断当前网络



直接上代码:

-(void)getNetWorkNotificationCenter
{
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusNotReachable:{
                [CHObjectClass showMastToast:@"网络无连接!"];
                break;
            }
            case AFNetworkReachabilityStatusReachableViaWiFi:{
                [CHObjectClass showMastToast:@"您正在使用WIFI网络"];
                break;
            }
            case AFNetworkReachabilityStatusReachableViaWWAN:{
                [CHObjectClass showMastToast:@"您正在使用2G/3G网络"];
                break;
            }
            default:
                break;
        }
        //NSLog(@"[[AFNetworkReachabilityManager sharedManager] isReachable] = %d",[[AFNetworkReachabilityManager sharedManager] isReachable]);
        //NSLog(@"网络状态返回: %@", AFStringFromNetworkReachabilityStatus(status));
    }];
}


你可能感兴趣的:(iOS)