Swift: how to programmatically get the unique identifier of an iOS device? [duplicate]

我的梦境 提交于 2019-12-25 18:47:20

问题


I am creating an iOS app that I need a unique identifier that has to be the same even user removes all content(reset to factory settings).

I know years ago we can get the UDID but right now we can only create an UUID which changes every time user re-install the app or reset device to factory settings.


回答1:


You can use the following

let id = UIDevice.current.identifierForVendor?.uuidString




回答2:


What I did was create a UUID string by NSUUID during the first time launch the app, and store this UUID string in the Keychain. Next time when you want to get an unique string, you can simply read this UUID string from Keychain. So this UUID can be treated as an UDID.




回答3:


This is intentionally impossible. You are not permitted to track the user this way. If you attempt to work around this restriction, Apple will likely break your technique in a future release (they've quietly broken several hacks people have used previously, generally without warning), and they may reject the app entirely.

The correct way to identify a device is with identifierForVendor. It is reset to a new value whenever the last of your apps is removed from the device and one of your apps is reinstalled. (By "your apps" I mean apps with the same start to their bundle id.) The fact that it can be reset is a system feature, and Apple does not allow you to circumvent it.



来源:https://stackoverflow.com/questions/58687743/swift-how-to-programmatically-get-the-unique-identifier-of-an-ios-device

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!