ios iOS7 - 设备唯一标识符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19013245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 01:42:07  来源:igfitidea点击:

iOS7 - Device unique identifier

iosobjective-cios7uniqueidentifier

提问by furqan kamani

Our iOS application is for specific users. So, we used device unique identifier for user identification. This approach works fine till iOS 6, because we are getting same value every time.

我们的 iOS 应用程序适用于特定用户。因此,我们使用设备唯一标识符来识别用户。这种方法在 iOS 6 之前都可以正常工作,因为我们每次都获得相同的价值。

NSString *strUniqueIdentifier = [[UIDevice currentDevice] uniqueIdentifier];

In iOS 7, above method is retuning different values and we are getting issues in user identification. iOS 7 apis provide following alternate.

在 iOS 7 中,上述方法正在重新调整不同的值,我们在用户识别方面遇到了问题。iOS 7 apis 提供以下替代。

NSUUID *oNSUUID = [[UIDevice currentDevice] identifierForVendor];
[strApplicationUUID setString:[oNSUUID UUIDString]];

I replaced "uniqueIdentifier" with "identifierForVendor", and created Ad hoc build. Installed build on both iOS 7 and iOS 6 devices. In iOS 7, so far, i am getting same value every time, but iOS 6 gives different values every time, when we delete and reinstall app.

我用“identifierForVendor”替换了“uniqueIdentifier”,并创建了临时构建。在 iOS 7 和 iOS 6 设备上安装构建。在 iOS 7 中,到目前为止,我每次都得到相同的值,但是当我们删除并重新安装应用程序时,iOS 6 每次都会给出不同的值。

Currently application is not available on App store. So i am not sure how this api works for App store build.

目前应用程序在 App Store 上不可用。所以我不确定这个 api 是如何用于 App Store 构建的。

Questions: 1) For appstore app, is "identifierForVendor" return same value for iOS 7 every time? or it may change when user delete and reinstall app in future? 2) Is any other alternative available for "unique identifier" in iOS 7 apis, which return same values for both iOS 6 and 7? 3) Any other suggestions...

问题:1) 对于 appstore 应用程序,“identifierForVendor”是否每次都为 iOS 7 返回相同的值?或者将来用户删除并重新安装应用程序时它可能会改变?2) iOS 7 apis 中的“唯一标识符”是否还有其他替代方法,它为 iOS 6 和 7 返回相同的值?3)其他建议...

采纳答案by Caleb

3) Any other suggestions...

3)其他建议...

You should consider strategies for identifying and authorizing the user instead of the device. Depending on a device-specific identifier prevents authorized users from switching devices without some sort of administrator interaction, and allows non-authorized users access if they happen to find/steal/borrow an authorized device. You can avoid these problems by relying on user credentials instead of device identifiers.

您应该考虑识别和授权用户而不是设备的策略。根据特定于设备的标识符可防止授权用户在没有某种管理员交互的情况下切换设备,并允许非授权用户在碰巧找到/窃取/借用授权设备时访问。您可以通过依赖用户凭据而不是设备标识符来避免这些问题。

回答by Dima

As you can see in the documentation here:

正如您在此处文档中所见:

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 of this property may be nil if the app is running in the background, before the user has unlocked the device the first time after the device has been restarted. If the value is nil, wait and get the value again later.

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. Therefore, if your app stores the value of this property anywhere, you should gracefully handle situations where the identifier changes.

对于来自在同一设备上运行的同一供应商的应用程序,此属性的值是相同的。对于来自不同供应商的同一设备上的应用程序以及不同供应商的不同设备上的应用程序,将返回不同的值。

如果应用程序在后台运行,则在设备重启后用户第一次解锁设备之前,此属性的值可能为零。如果值为 nil,则等待稍后再次获取该值。

当应用程序(或来自同一供应商的另一个应用程序)安装在 iOS 设备上时,此属性中的值保持不变。当用户从设备中删除该供应商的所有应用程序并随后重新安装其中一个或多个应用程序时,该值会发生变化。因此,如果您的应用程序将这个属性的值存储在任何地方,您应该优雅地处理标识符更改的情况。

In short, the identifier for a particular vendor will remain the same if at least one app by that vendor remains on the device. Once there are no more apps left (or in the case of a single app, it is reinstalled), the identifier can and will change. As far as I know, there should not be a difference on iOS 6 vs iOS 7, so any difference you are seeing is coincidental.

简而言之,如果该供应商的至少一个应用程序保留在设备上,则该供应商的标识符将保持不变。一旦没有更多的应用程序剩余(或者在单个应用程序的情况下,它被重新安装),标识符可以并且将会改变。据我所知,iOS 6 和 iOS 7 应该没有区别,所以您看到的任何差异纯属巧合。