我试图找出该机器连接到的SSID。我发现的所有东西都是针对iOS的,并没有用处。使用下面的代码,我得到一个错误,指出:''CNCopyCurrentNetworkInfo'不可用“,因为它是iOS特定的。什么是macOS等价物?在Swift 3中检索WiFi网络
斯威夫特3:从奎因,在苹果网络的神
import SystemConfiguration.CaptiveNetwork
var wifiNetwork = "Unknown"
if let interfaces = CNCopySupportedInterfaces() {
for i in 0..<CFArrayGetCount(interfaces){
let interfaceName: UnsafeRawPointer = CFArrayGetValueAtIndex(interfaces, i)
let rec = unsafeBitCast(interfaceName, to: AnyObject.self)
let unsafeInterfaceData = CNCopyCurrentNetworkInfo("\(rec)" as CFString)
if let unsafeInterfaceData = unsafeInterfaceData as? Dictionary<AnyHashable, Any> {
wifiNetwork = (unsafeInterfaceData["SSID"] as? String)!
}
}
}
CNCopyCurrentNetworkInfo仅可在IOS和tvOS根据[文档】(https://developer.apple.com/documentation/systemconfiguration/1614126-cncopycurrentnetworkinfo)。我无法在任何地方找到macOS的模拟器。 – user2625833