Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Update: Nov 4 2013</p> <p>Using Reachability 3.0 version on iOS7</p> <p>To build on top of @NR4TR and @codecaffeine's answers:</p> <p>There are 5 ways to do this (not compiled :)</p> <pre><code>#include &lt;ifaddrs.h&gt; #include &lt;arpa/inet.h&gt; //1 - Is www.apple.com reachable? Reachability *rHostName = [Reachability reachabilityWithHostName:@"www.apple.com"]; NetworkStatus s1 = [rHostName currentReachabilityStatus]; //2 - Is local wifi router or access point reachable? Reachability *rLocalWiFi = [Reachability reachabilityForLocalWiFi]; NetworkStatus s2 = [rLocalWiFi currentReachabilityStatus]; //3 - Is my access point connected to a router and the router connected to the internet? Reachability *rConnection = [Reachability reachabilityForInternetConnection]; NetworkStatus s3 = [rConnection currentReachabilityStatus]; //4 IPv4 standard addresses checking instead of host to avoid dns lookup step struct sockaddr_in saIPv4; inet_pton(AF_INET, "74.125.239.51", &amp;(saIPv4.sin_addr)); saIPv4.sin_len = sizeof(saIPv4); saIPv4.sin_family = AF_INET; Reachability *rIPv4 = [Reachability reachabilityWithAddress:&amp;saIPv4]; NetworkStatus s4 = [rIPv4 currentReachabilityStatus]; //5 IPv6 addresses checking instead of host to avoid dns lookup step struct sockaddr_in saIPv6; inet_pton(AF_INET, "2607:f8b0:4010:801::1014", &amp;(saIPv6.sin_addr)); saIPv6.sin_len = sizeof(saIPv6); saIPv6.sin_family = AF_INET; Reachability *rIPv6 = [Reachability reachabilityWithAddress:&amp;saIPv6]; NetworkStatus s5 = [rIPv6 currentReachabilityStatus]; </code></pre> <p>Handling status is same</p> <pre><code>if (ReachableViaWiFi == s1) return @"WiFi"; //@"WLAN" if (ReachableViaWWAN == s1) return @"Cellular"; //@"WWAN" return @"None"; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload