获取wifi无线ap的mac地址 获取唯一标识

#import 
/**
   获取wifi无线ap的mac地址
 - returns: <#return value description#>
 */
func getMAC()->(success:Bool,ssid:String,mac:String){
    
    if let cfa:NSArray = CNCopySupportedInterfaces() {
        for x in cfa {
            if let dict = CFBridgingRetain(CNCopyCurrentNetworkInfo(x as! CFString)) {
                let ssid = dict["SSID"]!
                let mac  = dict["BSSID"]!
                return (true,ssid as! String,mac as! String)
            }
        }
    }
    return (false,"","")
}

'CNCopySupportedInterfaces()' was deprecated in iOS 9.0:
For captive network applications,
this has been completely replaced by .
For other applications,
there is no direct replacement.
Please file a bug describing your use of this API to that we can consider your requirements as this situation evolves.

'CNCopyCurrentNetworkInfo' was deprecated in iOS 9.0:
For captive network applications,
this has been completely replaced by .
For other applications,
there is no direct replacement.
Please file a bug describing your use of this API to that we can consider your requirements as this situation evolves.

/**
 获取唯一标识

 - returns: <#return value description#>
 */
func getIdentifierForVendor() -> String?{
    return UIDevice.currentDevice().identifierForVendor?.UUIDString
}

调用示例:

        let wifo = getMAC()
        let deviceFlag = getIdentifierForVendor()
        
        let wifiName = wifo.ssid
        let wifiMac = wifo.mac
        
        let UUID = deviceFlag!
        
        print("wifiName:" + wifiName)
        print("wifiMac:" + wifiMac)
        print("UUID:" + UUID)

UUID&UDID

UUID(Universally Unique Identifier)
:2F426030-0A6C-4012-9259-59E533D2E970
UUID是Universally Unique Identifier的缩写,中文意思是通用唯一识别码.

UDID(Unique Device Identifier)
:c71a503fd518f8ddc6aedf5842f019d7eaf8eb11
UDID是Unique Device Identifier的缩写,中文意思是设备唯一标识.

你可能感兴趣的:(获取wifi无线ap的mac地址 获取唯一标识)