[AFNetworking练习3]监测网络链接状态

AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
    [manager startMonitoring];
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusUnknown:{
                [MyPublicFuntions AlertOkOnly:self Message:@"未知网络" OkHandler:nil Completion:nil];
                break;
            };
            case AFNetworkReachabilityStatusNotReachable:{
                [MyPublicFuntions AlertOkOnly:self Message:@"网络未链接" OkHandler:nil Completion:nil];
                break;
            };
            case AFNetworkReachabilityStatusReachableViaWWAN:{
                [MyPublicFuntions AlertOkAndCancel:self Message:@"正在使用3G/4G网络,是否继续?" OkHandler:^(UIAlertAction * _Nullable action) {
                    [self UploadExcute];
                } CancleHandler:nil Completion:nil];
                break;
            };
            case AFNetworkReachabilityStatusReachableViaWiFi:{
                [self UploadExcute];
                break;
            };
        }
    }];
没啥好说的了~~

你可能感兴趣的:(AFNetworking,状态)