我有一个功能,可以检测用户的当前SSID.不幸的是,这不再适用于iOS 12.这意味着它只是跳过了if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? {部分.也许这只是一个错误或它被弃用了.我在Apple Docs上找不到任何内容.在较旧的iOS 11,10和9设备上,它运行良好.
这是我的代码:
func getWiFiSsid() -> String? {
if let interfaces = CNCopySupportedInterfaces() as NSArray? {
for interface in interfaces {
if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? {
ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String
}
}
}
return ssid
}
Run Code Online (Sandbox Code Playgroud)