獲取連接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;
}