标签:
获取手机WiFi信息。
iOS9以前的方法,还是能用,警告就警告吧!iOS9以后使用的是苹果最新的API框架,NetworkExtension/NEHotspotHelper.h,这个框架,第一次开放了它的虚拟网卡,有时间了再介绍。
#import <SystemConfiguration/CaptiveNetwork.h>
- (void)viewDidLoad {
[super viewDidLoad];
NSDictionary *dict = [self SSIDInfo];
NSLog(@"dict:%@",dict);
NSString *SSID = dict[@"SSID"]; //WiFi名称
NSString *BSSID = dict[@"BSSID"]; //无线网的MAC地址
NSLog(@"SSID:%@ BSSID:%@",SSID,BSSID);
}
- (NSDictionary *)SSIDInfo
{
NSArray *ifs = (__bridge_transfer NSArray *)CNCopySupportedInterfaces();
NSDictionary *info = nil;
for (NSString *ifnam in ifs) {
info = (__bridge_transfer NSDictionary *)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
if (info && [info count]) {
break;
}
}
return info;
}
//可以直接根据
+ (BOOL)isConnectedWifi
{
NSString *ssid = [[self SSIDInfo] objectForKey:@"SSID"];
return ssid.length > 0;
}
标签:
原文地址:http://www.cnblogs.com/yyt-hehe-yyt/p/5685832.html