Skip to content

Instantly share code, notes, and snippets.

@nerdsupremacist
Forked from werediver/WiFiSsid.swift
Last active December 11, 2017 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerdsupremacist/bcbf3aebcc78b05f9d6398a9b184a9c0 to your computer and use it in GitHub Desktop.
Save nerdsupremacist/bcbf3aebcc78b05f9d6398a9b184a9c0 to your computer and use it in GitHub Desktop.
Get the connected Wi-Fi network SSID on iOS (in Swift).
import Foundation
import SystemConfiguration.CaptiveNetwork
func ssid() -> String? {
let interfaces = CNCopySupportedInterfaces() as [AnyObject]?
let interfaceNames = interfaces?.map { $0 as! CFString }
let interfaceDictionaries = interfaceNames?.flatMap { CNCopyCurrentNetworkInfo($0) as? [String : AnyObject] }
return interfaceDictionaries?.flatMap { $0[kCNNetworkInfoKeySSID as String] as? String }
.first
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment