5

I start monitoring like this in my AppDelegate:

[[AFNetworkReachabilityManager sharedManager] startMonitoring];

On my root controller I then need to check if reachability is available and I perform this action to decide how to draw my UI:

AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
NSLog(@"%s - %@", __FUNCTION__, AFStringFromNetworkReachabilityStatus([manager networkReachabilityStatus]));
switch ([manager networkReachabilityStatus]){
    case AFNetworkReachabilityStatusNotReachable:
        [self showNetworkUnreachable];
        break;
    default:
        [self hideNetworkUnreachable];
}

My issue is that here status is always unknown even if the device has connection.

Possibly AfNetworking is not the right tool to be used here. Any suggestion?

Andrea Campolonghi
  • 546
  • 2
  • 5
  • 15
  • I've never used AFNetworking to check the reachability, but I can't see anywhere the domain you are trying to reach. Pretty sure you have to deal with `+ (instancetype)managerForDomain:(NSString *)domain;`. Apple also suggest a reachability class : https://developer.apple.com/Library/ios/samplecode/Reachability/Listings/Reachability_Reachability_h.html – zbMax Dec 03 '13 at 16:34
  • I guess Reachability my be more suited to this kind of needs. I will test it out. Thanks – Andrea Campolonghi Dec 05 '13 at 13:15

1 Answers1

0

Not working in my case too. I used that instead:

- (BOOL)isInternetConnectionAvailable
{
    Reachability *reachability = [Reachability reachabilityForInternetConnection];
    NetworkStatus internetStatus = [reachability currentReachabilityStatus];
    if (internetStatus != NotReachable) {
        return YES;
    }
    else
    {
        NSLog(@"NO INTERNET CONNECTION");
        return NO;
    }
}
Nike Kov
  • 12,630
  • 8
  • 75
  • 122