如何在Swift中获取所有先前连接的Wi-Fi网络? [英] How to get all previously connected Wi-Fi networks in Swift?

查看:80
本文介绍了如何在Swift中获取所有先前连接的Wi-Fi网络?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道不可能获得所有可用的Wi-Fi网络,并且有可能获得当前连接的Wi-Fi网络的信息,如果我错了,请纠正我.

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

I know it's not possible to get all available Wi-Fi networks and it's possible to get the information of current connected Wi-Fi network, correct me if I'm wrong.

I just want to know the feasibility of getting the information of all previously connected Wi-Fi networks, Please help me by sharing your experience.

仅供参考,
我正在使用以下代码获取当前已连接的Wi-Fi网络的信息,并且工作正常.

FYI,
I'm using the following code get current connected Wi-Fi network's info and it's working fine.

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的钥匙串中.如果您可以访问iPhone SDK,则可以根据需要随意摆弄,但是我将保留它,因为那将是StackOverflow的答案. 来源

From a stock iPhone this is not possible from the settings. The information that you want is stored in the iPhone's keychain. If you have access to the iPhone SDK you can start messing around if you like, but I will leave it at that since that would be a StackOverflow answer. Source

如果启用了ICloud钥匙串,则可以获取此数据.否则,您将无法执行. 来源您可以使用 kishikawakatsumi/KeychainAccess 或自己动手做. >这是保存和检索钥匙串值的自制代码. 它是适用于iOS和OS X的Keychain的简单快速包装器.

If you have ICloud Keychain enabled, it is possible to fetch this data. Otherwise, you can't. Source You can use kishikawakatsumi/KeychainAccess or do it yourself. Here is homemade code to save and retrieve keychain values. It is a simple swift wrapper for Keychain that works on iOS and OS X

这篇关于如何在Swift中获取所有先前连接的Wi-Fi网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆