8vius
8vius

Reputation: 5836

Checking if Wi-Fi is available but internet isn't on iOS

I have this very weird case right now with an app I'm working on. The Wi-Fi network I'm testing it on has no internet enabled, yet it still shows that I have a conexión when using Reachability. How can I check for this case so I can tell the user there is no connection available?

Upvotes: 1

Views: 180

Answers (2)

alfwatt
alfwatt

Reputation: 2020

Define 'connection', there are several layers of connections that are key to getting working Internet service via Wi-Fi:

  • Layer 1 (Physical Link) is the radio in range?
  • Layer 2 (MAC) see above for the most part, but conflicting MAC addresses can cause issues
  • Layer 3 (IP) did we get an IP address from DHCP/BOOTP or Static configuration?
  • Layer 3 (GW) can we reach the gateway?
  • Layer 3 (ROUTE) can we reach the next-hop router?
  • Layer 7 (DNS) can we reach the DNS servers? Are we being spoofed or captivated?

Once all those things are working, you should have 'working Wi-Fi'

Upvotes: 0

Andy Sinclair
Andy Sinclair

Reputation: 2293

You need to use reachabilityWithHostName (I presume you are using reachabilityForInternetConnection or reachabilityForLocalWiFi) to check if you can reach a particular external hostname.

For example, this code will return YES if there is no internet connection:

Reachability *reachability = [Reachability reachabilityWithHostName:@"www.apple.com"];
if ([reachability currentReachabilityStatus] == NotReachable)
     return YES;

Upvotes: 1

Related Questions