swift3.0获取当前使用wifi SSID和SSID列表

前端之家收集整理的这篇文章主要介绍了swift3.0获取当前使用wifi SSID和SSID列表前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
func kGetUsedSSID()->String{
    let interfaces = CNCopySupportedInterfaces()
    var ssid = ""
    if interfaces != nil {
        let interfacesArray = CFBridgingRetain(interfaces) as! Array<AnyObject>
        if interfacesArray.count > 0 {
            //获取当前使用wifi
//            let interfaceName = interfacesArray[0] as! CFString
//            let ussafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName)
//            if (ussafeInterfaceData != nil) {
//                let interfaceData = ussafeInterfaceData as! Dictionary<String,Any>
//                ssid = interfaceData["SSID"]! as! String
//            }
            //获取wifi列表
            for name in interfacesArray {
                let interfaceName = name as! CFString
                let ussafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName)
                if (ussafeInterfaceData != nil) {
                    let interfaceData = ussafeInterfaceData as! Dictionary<String,Any>
                    ssid = interfaceData["SSID"]! as! String
                }
            }
        }
    }
    return ssid
}

猜你在找的Swift相关文章