SystemConfiguration.framework可以實現(xiàn)相關(guān)功能。
依賴下面三個相關(guān)頭文件:
#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;
}