gpt4 book ai didi

ios - 如何在 Swift 中获取所有以前连接的 Wi-Fi 网络?

转载 作者:行者123 更新时间:2023-11-28 06:52:10 27 4
gpt4 key购买 nike

我知道获取所有可用的Wi-Fi网络是不可能的,但是可以获取当前连接的Wi-Fi网络的信息,如果我错了请纠正我。

我只是想知道获取所有以前连接过的Wi-Fi网络信息的可行性,请分享您的经验帮助我。

仅供引用,
我正在使用以下代码获取当前连接的 Wi-Fi 网络的信息,它工作正常。

var currentSSID: String!
let interfaces:CFArray! = CNCopySupportedInterfaces()
for i in 0..<CFArrayGetCount(interfaces) {
let interfaceName: UnsafePointer<Void>
= CFArrayGetValueAtIndex(interfaces, i)
let rec = unsafeBitCast(interfaceName, AnyObject.self)
let unsafeInterfaceData = CNCopyCurrentNetworkInfo("\(rec)")
if unsafeInterfaceData != nil {
let interfaceData = unsafeInterfaceData! as Dictionary!
currentSSID = interfaceData["SSID"] as! String
} else {
currentSSID = ""
}
print(currentSSID)
}

最佳答案

在普通 iPhone 中,这无法通过设置实现。您需要的信息存储在 iPhone 的钥匙串(keychain)中。如果您可以访问 iPhone SDK,您可以随意开始,但我会保留它,因为那将是 StackOverflow 的答案。 Source

如果您启用了 ICloud 钥匙串(keychain),则可以获取此数据。否则,你不能。 Source您可以使用 kishikawakatsumi/KeychainAccess或者自己做。 Here is homemade code to save and retrieve keychain values.它是适用于 iOS 和 OS X 的钥匙串(keychain)的简单快速包装器

关于ios - 如何在 Swift 中获取所有以前连接的 Wi-Fi 网络?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34586378/

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