Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine whether iPhone is really connected to the internet or just behind a restricted hotspot

I'm having quite a lot of trouble on identifying rigorously the kind of network access an iPhone has. I have seen many questions like this one on StackOverflow but none of them helped me. For example I have already seen this: How to check for an active Internet connection on iOS or OSX?

But I want to know precisely when the 3 following cases occur:

  1. Wifi and 3G are disabled

  2. Wifi or 3G are enabled but there is no internet connection. It could be due to 3G not really working, even though it is showing up on the status bar, or the WiFi is a hotspot asking to log in before letting you access the Internet or last scenario: The WiFi source is a local network but does not provide any Internet connection.

  3. Everything works fine

Of course I have tried various stuff, like this for instance:

// 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 seems just to say wether Wifi or 3G are enabled and does not check for possible internet restrictions. I would be highly delighted by any answer helping me identifying the three scenarios.

Of course analyzing a direct HTTP request output from a personal server API returning a specific byte sequence would work but that is not what I would like to do. I'd prefer using any kind of Reachability API.

I've used Apple's reachability API, it does not seem to recognize hotspot redirections.

If this is not possible with the Reachability APIs, then what would be the lowest resource-consuming method to make a simple request to a server, check that it is reachable before a specified timeout, and that the URL was not redirected to a hotspot login page (maybe only check the headers, not the whole server byte sequence output)? Is it a good idea to run such a script every 15 seconds, or would it use too much battery and/or network data?

like image 222
Valentin Mercier Avatar asked Jul 30 '14 15:07

Valentin Mercier


1 Answers

The simplest method to check outbound connectivity is to GET Google's generate204 page 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 the OS uses

like image 161
chedabob Avatar answered Oct 22 '22 15:10

chedabob