swift 获取当前的WiFi AP信息
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift 获取当前的WiFi AP信息相关的知识,希望对你有一定的参考价值。
> http://www.yuukinishiyama.com/2018/10/23/wifi-ap-info-swift4/
> 需要開發者帳號
![](https://raw.githubusercontent.com/WingCH/Image/master/20190623171807.png)
會自動生成呢個 or 可能出現係info.plist
![](https://raw.githubusercontent.com/WingCH/Image/master/20190623171829.png)
如果無整既話以下既code會出nil
```swift
import UIKit
import SystemConfiguration.CaptiveNetwork
struct NetworkInfo {
public let interface:String
public let ssid:String
public let bssid:String
init(_ interface:String, _ ssid:String,_ bssid:String) {
self.interface = interface
self.ssid = ssid
self.bssid = bssid
}
}
class NetworkInfos: NSObject {
func getNetworkInfos() -> Array<NetworkInfo> {
// https://forums.developer.apple.com/thread/50302
guard let interfaceNames = CNCopySupportedInterfaces() as? [String] else {
print("no interfaceNames")
return []
}
let networkInfos:[NetworkInfo] = interfaceNames.compactMap{ name in
print(name)
guard let info = CNCopyCurrentNetworkInfo(name as CFString) as? [String:AnyObject] else {
print("no info")
return nil
}
guard let ssid = info[kCNNetworkInfoKeySSID as String] as? String else {
print("no ssid")
return nil
}
guard let bssid = info[kCNNetworkInfoKeyBSSID as String] as? String else {
print("no bssid")
return nil
}
return NetworkInfo(name, ssid,bssid)
}
return networkInfos
}
}
```
```
//use
print(NetworkInfos.init().getNetworkInfos())
//result
[ou_fyp.NetworkInfo(interface: "en0", ssid: "OUHK-Student", bssid: "34:fc:b9:6c:41:d4")]
```
//Empty
以上是关于swift 获取当前的WiFi AP信息的主要内容,如果未能解决你的问题,请参考以下文章
android里有获取周围所有wifi ap 的信号强度的方法么?
如何获取 wifi AP 列表并从 Windows 商店应用程序连接到一个 AP
可使用 Swift 语言访问 WIFI
请教怎样配置ESP8266的WiFi帐户及密码
如何在 .net 中获取可用的 wifi AP 及其信号强度?
ESP32-IDF 05-2 WIFI-esp32获取温度和天气信息