No one of the solutions found in this other question Get SSID in Swift 2 works because CaptiveNetwork framework was deprecated in Swift 2.0
In Swift 1.2 a use this function:
func getSSID() -> String {
let interfaces = CNCopySupportedInterfaces()
if interfaces == nil {
return ""
}
//let interfacesArray = interfaces.takeRetainedValue() as! [String]
let interfacesArray = Array(arrayLiteral: interfaces)
if interfacesArray.count <= 0 {
return ""
}
let interfaceName = String(interfacesArray[0])
let unsafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName)
if unsafeInterfaceData == nil {
return ""
}
let interfaceData = unsafeInterfaceData.takeRetainedValue() as Dictionary!
print(interfaceData["SSID"], terminator: "")
return interfaceData["SSID"] as! String
}
But the following code does not work anymore..