How to get current Wi-Fi network name after Yosemite in Swift?

In Mavericks, I used [CWInterface interface]to capture the current network. This means that it is deprecated for Yosemite.

As usual, there are no recommendations on this topic in the Apple documentation.

So, how can I get the current Wifi network name in Yosemite with Swift?

+2
source share
2 answers

So, I figured it out. If you pass nilin interfaceName, it will provide you with the currently connected Wi-Fi network. Then you can call ssid()to get the network name.

Same: CWInterface(interfaceName: nil).ssid()

+3
source

Xcode 10.2 • Swift 5 OSX Mojave

import CoreWLAN

var ssidName: String {
    return CWWiFiClient.shared().interface(withName: nil)?.ssid() ?? ""
}
+4
source

All Articles