Skip to content

Instantly share code, notes, and snippets.

@czwen
Last active August 16, 2017 10:21
Show Gist options
  • Save czwen/76a26fd9513d8d74be3723c64e17ae55 to your computer and use it in GitHub Desktop.
Save czwen/76a26fd9513d8d74be3723c64e17ae55 to your computer and use it in GitHub Desktop.
check wifi toggle status
#import <ifaddrs.h>
#import <net/if.h>
- (BOOL) isWiFiEnabled {
NSCountedSet * cset = [NSCountedSet new];
struct ifaddrs *interfaces;
if( ! getifaddrs(&interfaces) ) {
for( struct ifaddrs *interface = interfaces; interface; interface = interface->ifa_next) {
if ( (interface->ifa_flags & IFF_UP) == IFF_UP ) {
[cset addObject:[NSString stringWithUTF8String:interface->ifa_name]];
}
}
}
return [cset countForObject:@"awdl0"] > 1 ? YES : NO;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment