iOS中获取wifi的名称

2018-05-09  本文已影响0人  陈藩

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对象时用的,具体的原理还在了解中

上一篇下一篇

猜你喜欢

热点阅读