获取连接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:
<pre>
@textblock
Keys : Values
=======================================
kCNNetworkInfoKeySSIDData : CFDataRef
kCNNetworkInfoKeySSID : CFStringRef
kCNNetworkInfoKeyBSSID : CFStringRef
@/textblock
</pre>
@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;
}