//获取当前连接网络的ssid和bssid
- (id)fetchSSIDInfo {
NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
MYLog(@"Supported interfaces: %@", ifs);
id info = nil;
for (NSString *ifnam in ifs) {
info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
MYLog(@"%@ => %@", ifnam, info);
if (info && [info count]) { break; }
}
return info;
}
self.ssid = [wifiInfo valueForKey:@"SSID"];//wifi名字
self.bssid = [wifiInfo valueForKey:@"BSSID"];
但是在iOS13以后就得换方法了
//获取当前连接网络的ssid和bssid
-
(id)fetchSSIDInfo {
NEHotspotConfigurationManager 是IOS 11刚刚推出的用户获取WiFi信息的框架。
CFArrayRef wifiInterfaces = CNCopySupportedInterfaces();
id info = nil;NSArray *interfaces = (__bridge NSArray *)wifiInterfaces;
for (NSString *interfaceName in interfaces) {
CFDictionaryRef dictRef = CNCopyCurrentNetworkInfo((__bridge CFStringRef)(interfaceName)); if (dictRef) { info = (__bridge NSDictionary *)dictRef; CFRelease(dictRef); }
}
CFRelease(wifiInterfaces);
return info;
}
self.ssid = [wifiInfo valueForKey:@"SSID"];//wifi名字
self.bssid = [wifiInfo valueForKey:@"BSSID"];