AFNetworking 2.0 Reachability not working

流过昼夜 提交于 2020-02-01 05:07:18

问题


I'm having some trouble making AFNetworking Reachability module to work. I have setup my AFHTTPRequestOperationManager with a ReachabilityStatusChangeBlock but it's never being called.

self.manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:@"http://192.168.1.2:3000"]];
    self.manager.responseSerializer = [AFJSONResponseSerializer serializer];
    NSOperationQueue *operationQueue = self.manager.operationQueue;
    [self.manager.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusNotReachable:
            // we need to notify a delegete when internet conexion is lost.
            // [delegate internetConexionLost];
                NSLog(@"No Internet Conexion");
            break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
                NSLog(@"WIFI");
            break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                NSLog(@"3G");
            break;
          default:
            NSLog(@"Unkown network status");
            [operationQueue setSuspended:YES];
            break;
        }

I have imported SystemConfiguration/SystemConfiguration.h in my .pch as the documentation says. Every time i ask for the status i get the value -1.

Any help?

UPDATE:

I add my PodFile here:

pod 'AFNetworking'              ,'~> 2.0.0'
pod 'AFNetworking/Reachability' ,'~> 2.0.0'

回答1:


I needed to start the reachability monitor.

[self.manager.reachabilityManager startMonitoring]; 

I find it by accident, documentation should state this in my opinion.



来源:https://stackoverflow.com/questions/19232622/afnetworking-2-0-reachability-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!