Determine if iPhone is really connected to the Internet or just for a limited access point

I have quite a few problems with accurately determining the type of network access the iPhone has. I saw a lot of questions like this on StackOverflow, but none of them helped me. For example, I have already seen this: How to check the active Internet connection on iOS or OSX?

But I want to know exactly when the following three cases occur:

  • Wi-Fi and 3G disabled

  • Wi-Fi or 3G is available, but there is no internet connection. This may be due to the fact that 3G does not work, even if it is displayed in the status bar, or Wi-Fi is a hot spot asking for a login before allowing access to the Internet or the last scenario: the WiFi source is a local network but do not provide any internet connection.

  • Everything works perfectly

Of course, I tried different things, for example, for example:

// Allocate a reachability object Reachability* reach = [Reachability reachabilityWithHostname:@"www.google.com"]; // Set the blocks reach.reachableBlock = ^(Reachability*reach) { /* NOT REACHABLE */ dispatch_async(dispatch_get_main_queue(), ^{ iarcSBInternetWarning.visible = NO; }); }; reach.unreachableBlock = ^(Reachability*reach) { /* REACHABLE */ iarcSBInternetWarning.visible = YES; }; // Start the notifier, which will cause the reachability object to retain itself [reach startNotifier]; 

But this, apparently, simply means that Wi-Fi or 3G is turned on and does not check for possible Internet restrictions. I would be very pleased with any answer that helps me identify three scenarios.

Of course, analyzing a direct HTTP request request from a personal API server returning a specific sequence of bytes will work, but this is not what I would like to do. I would prefer to use any API to increase accessibility.

I used Apple's reachability API, it doesn't seem to recognize hotspot redirects.

If this is not possible with the Reachability APIs, then what will be the lowest resource-intensive method for a simple server request, make sure it is reached before the specified timeout and that the URL is not redirected to the hot spot login page (maybe check only the headers , but not the entire output of the server byte sequence)? Is it a good idea to run such a script every 15 seconds or use too much battery and / or network data?

+6
source share
1 answer

The easiest way to check outgoing calls is to getGET generate204 and check the response code

http://www.google.com/generate_204

Or you can use

http://www.apple.com/library/test/success.html , which is the page used by the OS

+4
source

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


All Articles