【问题标题】:Getting two different device IDs from same iphone从同一部 iPhone 获取两个不同的设备 ID
【发布时间】:2017-12-17 18:53:56
【问题描述】:

当我得到它from itunes 并且像这样以编程方式时,我的 iphone 得到了不同的 UDID

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

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

【问题讨论】:

  • 您无法以编程方式获取 UDID。 identifierForVendor 是唯一标识符,但如果您的应用被删除并重新安装,它可能会发生变化。
  • 是的,但正如 adarshaU 提到的(已接受的答案),我们可以将 UDID 存储在钥匙串中,并在重新安装后保持对设备的限制。

标签: ios iphone swift3 udid


【解决方案1】:

一个最简单的方法是通过将 identifierForVendor 存储在钥匙串中来解决这个问题。即使您卸载应用程序,密钥的值也保持不变。许多第三方库可用于执行此操作。其中之一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 ?? ""
    }
}

【讨论】:

  • 在 IOS 7 之后,这似乎是最好的方法。工作就像一个魅力谢谢你
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-11
  • 2015-07-25
  • 1970-01-01
  • 1970-01-01
  • 2018-06-23
  • 2019-07-28
  • 1970-01-01
相关资源
最近更新 更多