获取已经连接的WiFi信息
示例代码
// 导入头文件
#import <SystemConfiguration/CaptiveNetwork.h>
// 获取已连接WiFi
+ (NSDictionary *)readSSIDInfoList
{
NSArray *ifs = (id)CFBridgingRelease(CNCopySupportedInterfaces());
NSLog(@"%s: Supported interfaces: %@", __func__, ifs);
NSDictionary *info = nil;
for (NSString *ifnam in ifs)
{
info = (id)CFBridgingRelease(CNCopyCurrentNetworkInfo((CFStringRef)ifnam));
if (info && [info count])
{
break;
}
}
return info;
}
调用
NSDictionary *dict = [NSObject readSSIDInfoList];
NSLog(@"dict = %@", dict);
// 打印结果
2017-10-27 09:41:44.243 AirQuality[2791:923388] dict = {
BSSID = "bc:xx:xx:xx:2a:31";
SSID = devZhang;
SSIDDATA = <7a66616e 67736661 6f6665>;
}