Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AFNetworking 2.0 Reachability not working

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'
like image 844
bilby91 Avatar asked Nov 29 '22 02:11

bilby91


1 Answers

I needed to start the reachability monitor.

[self.manager.reachabilityManager startMonitoring]; 

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

like image 70
bilby91 Avatar answered Dec 10 '22 12:12

bilby91