我試圖找出該機器連接到的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