gpt4 book ai didi

ios - CNCopyCurrentNetworkInfo 不适用于 iOS 14

转载 作者:行者123 更新时间:2023-12-01 16:19:51 24 4
gpt4 key购买 nike

我有一个使用 WIFI 连接到外部设备的应用程序,我曾经通过检查 WIFI SSID 来验证 iPhone 是否已连接到设备。这在 iOS 13 发布时被阻止,我通过请求获取 SSID 的位置权限来修复它。
我现在尝试使用启用了位置服务的 iOS 14 测试版,但无法获取 WIFI SSID,但是相同的代码适用于 iOS 13。
这是我打电话时得到的日志 CNCopyCurrentNetworkInfo

nehelper sent invalid result code [1] for Wi-Fi information request

nehelper sent invalid response: <dictionary: 0x1e815f3e0> { count = 1, transaction: 0, voucher = 0x0, contents =
"XPCErrorDescription" => <string: 0x1e815f548> { length = 18, contents = "Connection invalid" }
}

nehelper sent invalid response for Wi-Fi information request: <dictionary: 0x1e815f3e0> { count = 1, transaction: 0, voucher = 0x0, contents =
"XPCErrorDescription" => <string: 0x1e815f548> { length = 18, contents = "Connection invalid" }
知道如何解决这个问题吗?
谢谢

更新:只有在请求位置访问时打开了精确位置才有效

最佳答案

我使用以下方法在 iOS 14 及更早版本中实现此目的。
导入网络扩展

func getNetworkInfo(compleationHandler: @escaping ([String: Any])->Void){

var currentWirelessInfo: [String: Any] = [:]

if #available(iOS 14.0, *) {

NEHotspotNetwork.fetchCurrent { network in

guard let network = network else {
compleationHandler([:])
return
}

let bssid = network.bssid
let ssid = network.ssid
currentWirelessInfo = ["BSSID ": bssid, "SSID": ssid, "SSIDDATA": "<54656e64 615f3443 38354430>"]
compleationHandler(currentWirelessInfo)
}
}
else {
#if !TARGET_IPHONE_SIMULATOR
guard let interfaceNames = CNCopySupportedInterfaces() as? [String] else {
compleationHandler([:])
return
}

guard let name = interfaceNames.first, let info = CNCopyCurrentNetworkInfo(name as CFString) as? [String: Any] else {
compleationHandler([:])
return
}

currentWirelessInfo = info

#else
currentWirelessInfo = ["BSSID ": "c8:3a:35:4c:85:d0", "SSID": "Tenda_4C85D0", "SSIDDATA": "<54656e64 615f3443 38354430>"]
#endif
compleationHandler(currentWirelessInfo)
}
}



获取当前网络信息:
var currentNetworkInfo: [String: Any] = [:]

getNetworkInfo { (wifiInfo) in

currentNetworkInfo = wifiInfo

}

关于ios - CNCopyCurrentNetworkInfo 不适用于 iOS 14,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63130232/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com