http://www.yuukinishiyama.com/2018/10/23/wifi-ap-info-swift4/
需要開發者帳號
會自動生成呢個 or 可能出現係info.plist
如果無整既話以下既code會出nil
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")]