iOS获取WiFi的Mac地址

释放双眼,带上耳机,听听看~!
获取连接WiFi的MacAddress
SystemConfiguration.framework里面有CaptiveNetwork类,

/*!
@function CNCopyCurrentNetworkInfo
@discussion Returns the Network Info for the specified interface.
For example, Network Info dictionary will contain the following
keys, and values:

    @textblock
    Keys                      : Values
    =======================================
    kCNNetworkInfoKeySSIDData : CFDataRef
    kCNNetworkInfoKeySSID     : CFStringRef
    kCNNetworkInfoKeyBSSID    : CFStringRef
    @/textblock
@param interfaceName Name of the interface you are interested in
@result Network Info dictionary associated with the interface.
Returns NULL if an error was encountered.
You MUST release the returned value.
*/
CFDictionaryRef __nullable
CNCopyCurrentNetworkInfo (CFStringRef interfaceName) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_1);
通过如下方法获取wifi名称和wifi macAddress,ssid代表wifi名称,bssid表示wifi macAddress。

+(NSString *)MacAddress
{
NSArray *ifs = CFBridgingRelease(CNCopySupportedInterfaces());
id info = nil;
for (NSString *ifnam in ifs) {
info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((CFStringRef)ifnam);
if (info && [info count]) {
break;
}
}
NSDictionary *dic = (NSDictionary *)info;
NSString *ssid = [[dic objectForKey:@"SSID"] lowercaseString];
NSString *bssid = [dic objectForKey:@"BSSID"];
NSLog(@"ssid:%@ \nssid:%@",ssid,bssid);
return bssid;
}

 

人已赞赏
iOS文章

ios获取设备IP地址Mac地址

2019-12-23 11:31:43

iOS文章

iOS 获取 Mac 地址

2019-12-23 12:37:06

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索