作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道获取所有可用的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/
我是一名优秀的程序员,十分优秀!