美文网首页xcode10
获取SSID,Xcode 10

获取SSID,Xcode 10

作者: 白色天空729 | 来源:发表于2018-10-11 16:46 被阅读152次

参考网站:https://www.jianshu.com/p/5fa628452b1b
iOS12之后,可能获取不到设备的ssid啦。

系统设置如下:
打开允许访问wifi 权限


image.png
func fetchSSIDInfo() -> [String: Any] {
        var interface = [String: Any]()
        if let interfaces = CNCopySupportedInterfaces() {
            for i in 0..<CFArrayGetCount(interfaces){
                let interfaceName = CFArrayGetValueAtIndex(interfaces, i)
                let rec = unsafeBitCast(interfaceName, to: AnyObject.self)
                guard let unsafeInterfaceData = CNCopyCurrentNetworkInfo("\(rec)" as CFString) else {
                    return interface
                }
                guard let interfaceData = unsafeInterfaceData as? [String: Any] else {
                    return interface
                }
                interface = interfaceData
            }
        }
        return interface
    }

参考:
https://stackoverflow.com/questions/31555640/how-to-get-wifi-ssid-in-ios9-after-captivenetwork-is-deprecated-and-calls-for-wi

相关文章

网友评论

    本文标题:获取SSID,Xcode 10

    本文链接:https://www.haomeiwen.com/subject/csnbaftx.html