I am using AFNetworking 2.2.1 and trying to use the AFNetworkReachabilityManager to check if a certain domain is reachable, but it always return NO. Maybe I am not using this correctly and would appreciate any pointers.
AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager managerForDomain:@"www.google.com"];
// always returns NO:
NSLog([manager isReachable] ? @"YES" : @"NO");
I also tried with the startMonitoring method (after the manager variable declaration), but with no luck:
[manager startMonitoring];
EDIT: As David pointed out, needed to add a status change block to get notified:
AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager managerForDomain:@"www.google.com"];
[manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status){
switch (status) {
case AFNetworkReachabilityStatusReachableViaWWAN:
case AFNetworkReachabilityStatusReachableViaWiFi:
case AFNetworkReachabilityStatusNotReachable:
NSLog(@"Never called");
break;
default:
NSLog(@"Never called");
break;
}
}];
[manager startMonitoring];
// always returns NO:
NSLog([manager isReachable] ? @"YES" : @"NO");