检测手机wifi有没有打开

http://segmentfault.com/q/1010000003901530/a-1020000003904523

- (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; }

SystemConfiguration.framework可以实现相关功能。
记得添加三个相关头文件

#import <ifaddrs.h>
#import <net/if.h>
#import <SystemConfiguration/CaptiveNetwork.h>
posted @ 2015-12-28 13:50  RDD  阅读(290)  评论(0编辑  收藏  举报