Im trying to use this code to get SSID
import Foundation
import SystemConfiguration.CaptiveNetwork
public class SSID {
class func getSSID() -> String{
var currentSSID = ""
let interfaces = CNCopySupportedInterfaces()
if interfaces != nil {
let interfacesArray = interfaces.takeRetainedValue() as [String : AnyObject]
if interfacesArray.count > 0 {
let interfaceName = interfacesArray[0] as String
let unsafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName)
if unsafeInterfaceData != nil {
let interfaceData = unsafeInterfaceData.takeRetainedValue() as Dictionary!
currentSSID = interfaceData[kCNNetworkInfoKeySSID] as! String
let ssiddata = NSString(data:interfaceData[kCNNetworkInfoKeySSIDData]! as! NSData, encoding:NSUTF8StringEncoding) as! String
// ssid data from hex
print(ssiddata)
}
}
}
return currentSSID
}
}
But in getting an error in this line
let interfacesArray = interfaces.takeRetainedValue() as [String : AnyObject]
The error is
Value of type 'CFArray?' has no member 'takeRetainedValue'
Thanks for your help
take(Un)RetainedValue()
calls, because the function do not return unmanaged objects anymore in Swift 2. See #30740500 for a similar Q&A. – Caprifoliaceous