How do I get the current wifi network name after Yosemite in Swift?

北城以北 提交于 2019-12-02 05:06:20

问题


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?


回答1:


Xcode 10.2 • Swift 5 or later • OSX Mojave

import CoreWLAN

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



回答2:


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()



来源:https://stackoverflow.com/questions/26517017/how-do-i-get-the-current-wifi-network-name-after-yosemite-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!