In Mavericks I was using [CWInterface interface]
to grab the currently connected network. That has been deprecated for Yosemite.
As usual Apple documentation provides no guidance on this topic.
So how can I get the currently connected Wifi network name in Yosemite with Swift?
Xcode 10.2 • Swift 5 or later • OSX Mojave
import CoreWLAN
var ssid: String {
return CWWiFiClient.shared().interface(withName: nil)?.ssid() ?? ""
}
So I figured it out. If you pass nil
to the interfaceName
, it will give you the currently connected wifi network. You can then call ssid()
to get the name of the network.
Like so: CWInterface(interfaceName: nil).ssid()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.