AFNetworking detect when wifi connection without active internet connection
afnetworking, ios, objective-c
Solution
Rather than using `[AFNetworkReachabilityManager sharedManager]` which just monitors network connectivity, you can use `[AFNetworkReachabilityManager managerForDomain:(NSString *)domain]` and pass an appropriate hostname - such as "www.google.com" - this way you can test whether the network you are connected to has Internet access - it can still be fooled by local DNS and a web server, but I would think that it is unlikely someone would do that.
Once you have your `AFNetworkReachabilityManager` you can set the change block as you do for the shared manager
Problem
I'm using `AFNetworking` and was wondering how to detect a scenario when user is connected to a wifi network without active internet connection. I reproduce this scenario buy powering a router without connecting the dsl line. ``` AFNetworking return AFNetworkReachabilityStatusReachableViaWiFi = 2 ``` my code: ``` [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { NSLog(@"Reachability: %@", AFStringFromNetworkReachabilityStatus(status)); self.isInternetAvialable = status > 0; }]; ``` thanks I refacotred the code to be like ``` AFNetworkReachabilityManager* manager = [AFNetworkReachabilityManager managerForDomain:@"http://www.google.com"]; [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { NSLog(@"Reachability: %@", AFStringFromNetworkReachabilityStatus(status)); self.isInternetAvialable = status > 0; }]; [manager startMonitoring]; ``` now the block never get called!