ios13获取wifi奇巧淫技

ios获取wifi名称
ios设备高版本获取wifi名称,目前因为隐私规定,需要获取地理位置
这里写下步骤,造福同行

ios13获取wifi奇巧淫技_第1张图片
Snip20200324_1.png
Snip20200324_2.png
Snip20200324_3.png
Snip20200324_5.png

OC还是swift,获取wifi名称的方法

swift

//获取用户使用wifi名称
    func getWifiName() -> String? {
        var wifiName : String = ""
        let wifiInterfaces = CNCopySupportedInterfaces()
        if wifiInterfaces == nil {
            return nil
        }
        let interfaceArr = CFBridgingRetain(wifiInterfaces!) as! Array
        if interfaceArr.count > 0 {
            let interfaceName = interfaceArr[0] as CFString
            let ussafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName)
            
            if (ussafeInterfaceData != nil) {
                let interfaceData = ussafeInterfaceData as! Dictionary
                wifiName = interfaceData["SSID"]! as! String
            }
        }
        return wifiName
    }

oc

//获取wifi信息
- (id)fetchSSIDInfo {
    NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
    NSLog(@"Supported interfaces: %@", ifs);
    id info = nil;
    for (NSString *ifnam in ifs) {
        info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
        NSLog(@"%@ => %@", ifnam, info);
        if (info && [info count]) { break; }
    }
    return info;
}

你可能感兴趣的:(ios13获取wifi奇巧淫技)