Getting two different device IDs from same iphone

那年仲夏 提交于 2019-12-31 03:49:05

问题


I am getting different UDIDs for my iphone when i get it from itunes and programatically like this

UDID:String = UIDevice.current.identifierForVendor!.uuidString

Basically im trying to acquire a unique identifier for my iphone just like we have mac address for android phones.


回答1:


one easiest way is to solve this issue by storing the identifierForVendor in keychain. even if you uninstall app ,value for the key remains same and its unchanged. many third party libraries available to perform this . one of them https://github.com/jrendel/SwiftKeychainWrapper.

func getGlobalUniqueIdentifierFromKeyChain()->String{

    let retrievedString: String? = KeychainWrapper.standard.string(forKey: "DeviceId")

    if  retrievedString == nil{
        if let deviceKey  = UIDevice.current.identifierForVendor?.uuidString{
            let _ = KeychainWrapper.standard.set(deviceKey, forKey: "DeviceId")
        }
    }

    if let globalID = KeychainWrapper.standard.string(forKey: "DeviceId"){
        return globalID
    }else{
        return UIDevice.current.identifierForVendor?.uuidString ?? ""
    }
}


来源:https://stackoverflow.com/questions/47858394/getting-two-different-device-ids-from-same-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!