Skip to content

Instantly share code, notes, and snippets.

@joshua24322
Last active October 4, 2019 17:41
Show Gist options
  • Save joshua24322/b0d19952990f3c3b111738efceb70b28 to your computer and use it in GitHub Desktop.
Save joshua24322/b0d19952990f3c3b111738efceb70b28 to your computer and use it in GitHub Desktop.
Get current SSID by CF-based APIs
// https://forums.developer.apple.com/thread/50302
func getSSID() -> [String] {
guard let interfacesName = CNCopySupportedInterfaces() as? [String] else { return [String()] }
return interfacesName.compactMap({ (name) in
guard let info = CNCopyCurrentNetworkInfo(name as CFString) as? [String: AnyObject] else { return nil }
guard let ssid = info[kCNNetworkInfoKeySSID as String] as? String else { return nil }
return ssid
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment