Skip to content

Instantly share code, notes, and snippets.

@eaigner
Created September 5, 2012 13:58
Show Gist options
  • Save eaigner/3636996 to your computer and use it in GitHub Desktop.
Save eaigner/3636996 to your computer and use it in GitHub Desktop.
Simple Wi-Fi check for iOS
#import <arpa/inet.h>
#import <ifaddrs.h>
#import <net/if.h>
BOOL localWiFiAvailable( void )
{
struct ifaddrs *addresses;
struct ifaddrs *cursor;
BOOL wiFiAvailable = NO;
if (getifaddrs(&addresses) != 0) return NO;
cursor = addresses;
while (cursor != NULL) {
if (cursor->ifa_addr->sa_family == AF_INET && !(cursor->ifa_flags & IFF_LOOPBACK))
{
// Check for WiFi adapter
if (strcmp(cursor->ifa_name, "en0") == 0)
{
wiFiAvailable = YES;
break;
}
}
cursor = cursor -> ifa_next;
}
freeifaddrs(addresses);
return wiFiAvailable;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment