iOS Question

AFNetworking 2.0 Reachability

I am trying to determine if the user is connected to the internet by using AFNetworking 2.0 and the "AFNetworkReachabilityManager", but it doesen't seem to work. It's always return that there is a valid internet connection, even though the internet is turned off.
This is my code:

-(BOOL)connected {

__block BOOL reachable;

[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {

switch (status) {
case AFNetworkReachabilityStatusNotReachable:
NSLog(@"No Internet Connection");
reachable = NO;
case AFNetworkReachabilityStatusReachableViaWiFi:

reachable = YES;
case AFNetworkReachabilityStatusReachableViaWWAN:
reachable = YES;
NSLog(@"Unkown network status");
reachable = NO;

[[AFNetworkReachabilityManager sharedManager] startMonitoring];

return reachable;


This method is called from my viewDidLoad method. Is there something wrong with my code, since it isn't working?

Answer Source

That's because that block is only executed when reachability changes.

To get the current status, you can do this:

- (BOOL)connected {
    return [AFNetworkReachabilityManager sharedManager].reachable;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download