Cannot detect internet connection with reachability reach for internet connection

I have a problem. I use the ForInternetConnection Accessibility reachability method to detect Internet accessibility, but instead I get the connection status, not the Internet status. I mean, if I go back to my Wi-Fi connection, this method gives me the correct indication that I have no connection, but if Wi-Fi is turned on and the Internet connection does not work, it does not seem to work. Any idea?

Best wishes

+6
source share
2 answers

Accessibility can only be used to determine if the iPhone has an Internet gateway connection. What is behind the gateway will not tell you. What if the LAN is reachable but you don’t have Internet access? How could the iPhone suggest that what it sees (LAN) is not the whole Internet?

You must make a real request to a real site. If this fails, there is a problem with your Internet connection, and with the Reachability results you can even figure out where the problem is. The easiest way is to make a request with NSUrlRequest, for example, http://www.google.com . (If google dies, you can assume that there are big problems, and then connecting to your application :)

+3
source

I use this in my application:

// Check for internet connection [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil]; internetReachable = [Reachability reachabilityForInternetConnection]; [internetReachable startNotifier]; // Check if a pathway to a random host exists hostReachable = [Reachability reachabilityWithHostName: @"www.apple.com"]; [hostReachable startNotifier]; 

and

 - (void) checkNetworkStatus:(NSNotification *)notice { // Called after network status changes NetworkStatus internetStatus = [internetReachable currentReachabilityStatus]; switch (internetStatus) { // Case: No internet case NotReachable: { internetActive = NO; // Switch to the NoConnection page NoConnectionViewController *notConnected = [[NoConnectionViewController alloc] initWithNibName:@"NoConnectionViewController" bundle:[NSBundle mainBundle]]; notConnected.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:notConnected animated:NO]; break; } case ReachableViaWiFi: { internetActive = YES; break; } case ReachableViaWWAN: { internetActive = YES; break; } } // Check if the host site is online NetworkStatus hostStatus = [hostReachable currentReachabilityStatus]; switch (hostStatus) { case NotReachable: { hostActive = NO; break; } case ReachableViaWiFi: { hostActive = YES; break; } case ReachableViaWWAN: { hostActive = YES; break; } } } 
+2
source

Source: https://habr.com/ru/post/910141/


All Articles