Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using Apple's Reachability code, I created a function that'll check this correctly without you having to include any classes.</p> <p>Include the SystemConfiguration.framework in your project.</p> <p>Make some imports:</p> <pre><code>#import &lt;sys/socket.h&gt; #import &lt;netinet/in.h&gt; #import &lt;SystemConfiguration/SystemConfiguration.h&gt; </code></pre> <p>Now just call this function:</p> <pre><code>/* Connectivity testing code pulled from Apple's Reachability Example: https://developer.apple.com/library/content/samplecode/Reachability */ +(BOOL)hasConnectivity { struct sockaddr_in zeroAddress; bzero(&amp;zeroAddress, sizeof(zeroAddress)); zeroAddress.sin_len = sizeof(zeroAddress); zeroAddress.sin_family = AF_INET; SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)&amp;zeroAddress); if (reachability != NULL) { //NetworkStatus retVal = NotReachable; SCNetworkReachabilityFlags flags; if (SCNetworkReachabilityGetFlags(reachability, &amp;flags)) { if ((flags &amp; kSCNetworkReachabilityFlagsReachable) == 0) { // If target host is not reachable return NO; } if ((flags &amp; kSCNetworkReachabilityFlagsConnectionRequired) == 0) { // If target host is reachable and no connection is required // then we'll assume (for now) that your on Wi-Fi return YES; } if ((((flags &amp; kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) || (flags &amp; kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0)) { // ... and the connection is on-demand (or on-traffic) if the // calling application is using the CFSocketStream or higher APIs. if ((flags &amp; kSCNetworkReachabilityFlagsInterventionRequired) == 0) { // ... and no [user] intervention is needed return YES; } } if ((flags &amp; kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) { // ... but WWAN connections are OK if the calling application // is using the CFNetwork (CFSocketStream?) APIs. return YES; } } } return NO; } </code></pre> <p>And it's <a href="https://en.wikipedia.org/wiki/IOS_5" rel="noreferrer">iOS&nbsp;5</a> tested for you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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