iOS 中可获取当前网络接口的 SSIDBSSID 信息,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
NSString *ssid = @"";
NSString *bssid = @"";
NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
NSDictionary *info;
if ([ifs count] > 0) {
for (NSString *ifname in ifs) {
info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifname);

NSString *ssidKey = (__bridge_transfer NSString *)kCNNetworkInfoKeySSID;
NSString *bssidKey = (__bridge_transfer NSString *)kCNNetworkInfoKeyBSSID;
if (info) {
ssid = info[ssidKey];
bssid = info[bssidKey];
NSLog(@"ssid: %@", ssid);
NSLog(@"bssid: %@", bssid);
}
}
}

需引入头文件:

#import <SystemConfiguration/CaptiveNetwork.h>

CNCopySupportedInterfaces 返回的是所有网络接口的名字,不过通常只有一个,如 en0, 然后根据获取的网络接口名得到对应于该网络接口的网络信息字典,该字典中包含了 SSID, BSSID, SSIDDATA 信息,字典中包含key在 CaptiveNetwork Info Keys 中有说明。

参考:

CaptiveNetwork Reference


目前已转行教育行业,欢迎加微信交流:CaryaLiu