Skip to content

Instantly share code, notes, and snippets.

@prat14k
Forked from werediver/WiFiSsid.swift
Created July 18, 2018 06:15
Show Gist options
  • Save prat14k/374246e79604ac7de219db7c69c68a37 to your computer and use it in GitHub Desktop.
Save prat14k/374246e79604ac7de219db7c69c68a37 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 getWiFiSsid() -> String? {
var ssid: String?
if let interfaces = CNCopySupportedInterfaces() as NSArray? {
for interface in interfaces {
if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? {
ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String
break
}
}
}
return ssid
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment