1.获取wifi的名称,先倒入框架
#import <SystemConfiguration/CaptiveNetwork.h>
2.实现的代码如下
NSArray *inforArr = (__bridge_transfer id)CNCopySupportedInterfaces();
for (NSString *inforStr in inforArr) {
NSDictionary *infoDict = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)inforStr);
NSLog(@"inforStr:%@",inforStr);
NSLog(@"inforDict:%@",infoDict);
NSString *str = infoDict[@"SSID"];
NSString *str2 = infoDict[@"BSSID"];
NSString *str3 = [[ NSString alloc] initWithData:infoDict[@"SSIDDATA"] encoding:NSUTF8StringEncoding];
}
3.打印log如下
inforStr:en0
inforDict:{
BSSID = "1c:60:de:a3:fb:44";
SSID = gege;
SSIDDATA = <67656765>;
}
4.其中 (__bridge_transfer id) 是用于在Core Foundation 对象转换为Foundation对象时用的,具体的原理还在了解中
网友评论