Search code examples
iphoneobjective-ciosreachability

Reachability iOS little help for wifi on vpn


I'm facing a little problem with the class Reachability and vpn or public internet gateways.

If the iPhone is connected to a public Wifi with some vpn or paying stuff the app crash. If I disable wifi and force through 3g everything works fine and if the wifi is a classic working wifi it works perfectly well too. So I know the problem is linked to those public wifi hotstop with login and passwords.

How can I test that the Wifi will work its way to the server and get the data back? Shouldn't reachability with host name do the trick? Looks like it returns reachableviaWifi even when a hostname is set.

Thank you!

Reachability * reach = [Reachability reachabilityWithHostName:@"www.mysoapp.com"];

NetworkStatus status = [reach currentReachabilityStatus];

if (status == NotReachable) {

    return NO;
}
else
    return YES;

Solution

  • Reachability only checks the first hop (on the way to the requested host). This is important in a mobile environment, as that first hop can be changing and dropping dynamically as the device moves.

    If you want to check all the way to the desired host, past the first hop, the best way is to actually try to connect to that host, and send and receive network packets (e.g. your app's regular network traffic). Then have the app present the user with options if the connection seems to be timing out, instead of having the app lock up or crash. Apple sometimes tests for the latter as part of their app review process, and uses failure (crashing or locking up if the network route breaks) as grounds for rejecting apps.