UIDevice uniqueIdentifier已弃用 - 现在该怎么办? [英] UIDevice uniqueIdentifier Deprecated - What To Do Now?

查看:300
本文介绍了UIDevice uniqueIdentifier已弃用 - 现在该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIDevice uniqueIdentifier属性已弃用 iOS5 及更高版本。没有替代方法或属性似乎可用或即将推出。

It has just come to light that the UIDevice uniqueIdentifier property is deprecated in iOS5 and above. No alternative method or property appears to be available or forthcoming.

我们的许多现有应用程序都严格依赖此属性来唯一标识特定设备。任何人都可以建议我们如何处理这个问题吗?

Many of our existing apps are tightly dependent on this property for uniquely identifying a particular device. Can anyone suggest any ideas how we might handle this problem going forward?

文档中的建议是......

The suggestion from the documentation is...


特殊注意事项

请勿使用uniqueIdentifier属性。要为您的应用创建特定
的唯一标识符,您可以调用 CFUUIDCreate 函数来创建 UUID ,并使用 NSUserDefaults 类将
写入默认数据库。

Do not use the uniqueIdentifier property. To create a unique identifier specific to your app, you can call the CFUUIDCreate function to create a UUID, and write it to the defaults database using the NSUserDefaults class.

但是,如果用户卸载并重新安装应用程序,则此值将不相同。

However this value won't be the same if a user uninstalls and re-installs the app.

推荐答案

UUID如果用户卸载并重新安装应用程序,则由 CFUUIDCreate 创建唯一:您每次都会获得一个新的。

A UUID created by CFUUIDCreate is unique if a user uninstalls and re-installs the app: you will get a new one each time.

但你可能希望它唯一,i。即当用户卸载并重新安装应用程序时,它应该保持不变。这需要一些努力,因为最可靠的每设备标识符似乎是MAC地址。您可以查询MAC 和将其用作UUID。

But you might want it to be not unique, i. e. it should stay the same when the user uninstalls and re-installs the app. This requires a bit of effort, since the most reliable per-device-identifier seems to be the MAC address. You could query the MAC and use that as UUID.

编辑:当然,需要始终查询同一界面的MAC。我想最好的选择是 en0 。 MAC始终存在,即使接口没有IP /已关闭。

One needs to always query the MAC of the same interface, of course. I guess the best bet is with en0. The MAC is always present, even if the interface has no IP/is down.

编辑2:正如所指出的那样由其他人,iOS 6以来的首选解决方案是 - [UIDevice identifierForVendor] 。在大多数情况下,您应该可以使用它作为旧的 - [UIDevice uniqueIdentifier] 的替代品(但是当应用程序启动时创建的UUID第一次是Apple似乎希望你使用的。)

Edit 2: As was pointed out by others, the preferred solution since iOS 6 is -[UIDevice identifierForVendor]. In most cases, you should be able use it as a drop-in replacement to the old -[UIDevice uniqueIdentifier] (but a UUID that is created when the app starts for the first time is what Apple seems to want you to use).

编辑3:所以这个重点不会丢失在评论噪音中:不要将 MAC 用作UUID,使用MAC 创建哈希。该哈希每次都会创建相同的结果,即使在重新安装和应用程序中也是如此(如果以相同的方式完成哈希)。无论如何,现在(2013)除了在iOS上需要稳定的设备标识符外,这是不再需要的。 6.0。

Edit 3: So this major point doesn't get lost in the comment noise: do not use the MAC as UUID, create a hash using the MAC. That hash will always create the same result every time, even across reinstalls and apps (if the hashing is done in the same way). Anyways, nowadays (2013) this isn't necessary any more except if you need a "stable" device identifier on iOS < 6.0.

编辑4:在iOS 7中,Apple现在总是在查询MAC时返回固定值以特别阻止 MAC作为ID 方案的基础。所以你现在真的应该使用 - [UIDevice identifierForVendor] 或创建每个安装的UUID。

Edit 4: In iOS 7, Apple now always returns a fixed value when querying the MAC to specifically thwart the MAC as base for an ID scheme. So you now really should use -[UIDevice identifierForVendor] or create a per-install UUID.

这篇关于UIDevice uniqueIdentifier已弃用 - 现在该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆