从同一个iPhone获取两个不同的设备ID

时间:2017-12-17 18:53:57

标签: ios iphone swift3 udid

当我得到from itunes时,我正在为我的iphone获取不同的UDID,并以此编程方式

$('input').keypress(function (evt) {
  if (/^([a-z\d] ?)+[a-z\d]$/i.test(this.value)) {
    alert('True');
  }
})

基本上我试图获取我的iphone的唯一标识符,就像我们有Android手机的mac地址一样。

1 个答案:

答案 0 :(得分:3)

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 ?? ""
    }
}