SystemConfiguration.framework可以实现相关功能。
依赖下面三个相关头文件:
#import <ifaddrs.h>
#import<net/if.h>
#import<SystemConfiguration/CaptiveNetwork.h>
-(BOOL)isWiFiEnabled{
NSCountedSet *cset = [NSCountedSetnew];
structifaddrs*interfaces;
if(!getifaddrs(&interfaces)){
for(structifaddrs*interface=interfaces;interface;interface=interface->ifa_next){
if((interface->ifa_flags&IFF_UP)==IFF_UP){
[cset addObject:[NSStringstringWithUTF8String:interface->ifa_name]];
}
}
}
return[cset countForObject:@"awdl0"]>1?YES:NO;
}