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 al
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[self checkNetworkReachability];
}
+(BOOL) isReachable{
return [AFNetworkReachabilityManager sharedManager].reachable;
}
+(void) checkNetworkReachability{
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
NSLog(@"Reachability: %@", AFStringFromNetworkReachabilityStatus(status));
// Check the reachability status and show an alert if the internet connection is not available
switch (status) {
case -1:
// AFNetworkReachabilityStatusUnknown = -1,
NSLog(@"The reachability status is Unknown");
break;
case 0:
// AFNetworkReachabilityStatusNotReachable = 0
NSLog(@"The reachability status is not reachable");
break;
case 1:
NSLog(@"The reachability status is reachable via wan");
[[NSNotificationCenter defaultCenter] postNotificationName:@"Network_Reachable" object:nil];
break;
case 2:
// AFNetworkReachabilityStatusReachableViaWiFi = 2
NSLog(@"The reachability status is reachable via WiFi");
[[NSNotificationCenter defaultCenter] postNotificationName:@"Network_Reachable" object:nil];
break;
default:
break;
}
}];
}