之前做过一个功能,关于获取当前连接WiFi名称。查找了一些方法,进行了总结。这些方法需要使用真机来测试才行。
引入系统#import<SystemConfiguration/CaptiveNetwork.h>
获取SSID --wifi名称
+ (NSString *)ssid
{
NSString *ssid = @"Not Found";
CFArrayRef myArray = CNCopySupportedInterfaces();
if (myArray != nil) {
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
if (myDict != nil) {
NSDictionary *dict = (NSDictionary*)CFBridgingRelease(myDict);
ssid = [dict valueForKey:@"SSID"];
}
}
return ssid;
}
获取MAC --MAC为网络接口物理地址,一般指电脑网卡的物理地址
+ (NSString *)bssid //获取macIP
{
NSString *bssid = @"Not Found";
CFArrayRef myArray = CNCopySupportedInterfaces();
if (myArray != nil) {
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
if (myDict != nil) {
NSDictionary *dict = (NSDictionary*)CFBridgingRelease(myDict);
bssid = [dict valueForKey:@"BSSID"];
}
}
return bssid;
}
这样我们就获取到了当前你所连接的WiFi名称啦!效果图如下: