iOS - 获取当前手机连接WIFI名称和MAC地址

最近项目需求里面有个获取当前手机连接Wifi的功能,在此记录一下方法。

1. 引入#import

2.获取当前手机连接Wifi的名称

+ (NSString *)getWifiName{
    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;
}

3.获取当前手机连接Wifi的mac地址

+ (NSString *)getWifiMacAddress{
    NSString *macIp = @"Not Found";
    CFArrayRef myArray = CNCopySupportedInterfaces();
    if (myArray != nil) {
        CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
        if (myDict != nil) {
            NSDictionary *dict = (NSDictionary*)CFBridgingRelease(myDict);
            macIp = [dict valueForKey:@"BSSID"];
        }
    }
    return macIp;
}

你可能感兴趣的:(iOS - 获取当前手机连接WIFI名称和MAC地址)