IOS: swift gets the name of the Wi-Fi connection and the mac address of the ap.
After searching for the Internet for half a day, they all use various copy versions, not the swift version. After several experiments, we finally completed integration. I would like to share with you the following code in xcode7.1.
1. Because the system library needs to be imported in swift, a bridge Header. h is required and added to the bridge file.
# Import
2. Add the following functions in the swift file.
Func getMAC ()-> (success: Bool, ssid: String, mac: String) {if let cfa: NSArray = CNCopySupportedInterfaces () {for x in cfa {if let dict = CFBridgingRetain (CNCopyCurrentNetworkInfo (x! CFString) {let ssid = dict [SSID]! Let mac = dict [BSSID]! Return (true, ssid! String, mac! String) }}return (false ,,)}
3. Call
Let x = getMAC () if x. success {print (x. mac) print (x. ssid )}