陈斌彬的技术博客

Stay foolish,stay hungry

AFNetworking HTTP Manager Reachability

模拟机下测试结果

img

主要代码

-(void)HTTPManagerReachability{
    NSURL *baseURL = [NSURL URLWithString:@"http://www.baidu.com"];
    AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:baseURL];

    NSOperationQueue *operationQueue = manager.operationQueue;
    [manager.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusReachableViaWWAN: NSLog(@"AFNetworkReachabilityStatusReachableViaWWAN");
            case AFNetworkReachabilityStatusReachableViaWiFi:
            {
                NSLog(@"AFNetworkReachabilityStatusReachableViaWiFi");
                [operationQueue setSuspended:NO];
            }
                break;
            case AFNetworkReachabilityStatusNotReachable:
            {
                NSLog(@"AFNetworkReachabilityStatusNotReachable");

            }
            default:
                [operationQueue setSuspended:YES];
                break;
        }
    }];

    [manager.reachabilityManager startMonitoring];
}