swift 2.2 中的不同 UUID

Different UUID in swift 2.2

之前Swift2.2每次打开应用UUID值都一样,现在每次打开都变

我使用这个代码:

UIDevice.currentDevice().identifierForVendor!.UUIDString

现在如何识别用户?

每次删除应用程序时,UUID 可能会发生变化。 如果您只是关闭并打开应用程序,它应该是一样的。 但如果您删除应用程序(或通过 xcode 重新安装),它可能会改变。

The value of this property is the same for apps that come from the same vendor running on the same device. A different value is returned for apps on the same device that come from different vendors, and for apps on different devices regardless of vendor.

The value in this property remains the same while the app (or another app from the same vendor) is installed on the iOS device. The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them. The value can also change when installing test builds using Xcode or when installing an app on a device using ad-hoc distribution. Therefore, if your app stores the value of this property anywhere, you should gracefully handle situations where the identifier changes.

请参阅此 link 了解更多信息。

有几个答案可以解释为什么 UUID 正在重置。有一个提供了 潜在 解决方法,但我认为它远非理想。但我想强调一些关于 UUID 的工作方式的重要内容,它作为 伟大的 解决方法,对生产或调试版本 绝对零影响 您的代码库或编译后的二进制文件。

The value in this property remains the same while the app (or another app from the same vendor) is installed on the iOS device. The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them.

要防止在开发 App-A 时更改此值,您只需安装来自同一供应商(您自己)的 App-B,并在 App-A 的开发生命周期内保持安装状态。这实际上就像开始一个空白的新 iOS 项目并将空白板安装到您的测试设备(使用相同的开发者帐户等)一样简单,然后在开发过程中永远不会再次卸载它。

App-B 为供应商(您自己)保留一个不变的 UUID,因此无论您删除并重新安装 App-A 多少次,它始终保持相同的 UUID。

这实际上似乎是 IMO 的一个错误。每次我在模拟器中 运行 我的应用程序时,它都会生成一个新的供应商 ID。您可能可以通过在第一次启动时将 ID 存储到 NSUserDefaults 中然后从 NSUserDefaults 中检索/比较值而不是从 identifierForVendor 中获取它来绕过它。这将在默认情况下保存静态供应商 ID,但理论上供应商 ID 仍将在每次启动时更改。

亲切的问候,

Krivvenz.

更新:我可以确认我也在同一个模拟器上安装了多个应用程序,但每次启动时供应商 ID 仍在变化。

更新 2:- 我已将此记录为 Apple 的错误 - 26195931。