ios - 以编程方式获取IOS设备的UDID?

标签 ios objective-c iphone udid

我想以编程方式获取 iOS 设备的 UDID。我正在使用以下代码来获取iOS设备的UDID。

NSUUID *uuid = [NSUUID UUID];
NSString *uuidString = uuid.UUIDString;

但是我得到的输出与我设备的实际 UDID 不同。

最佳答案

NSString* identifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; // IOS 6+
NSLog(@"output is : %@", identifier);

Swift 2.X(此处 X 表示 2.0 以后的所有版本)

let identifier: String = UIDevice.currentDevice().identifierForVendor().UUIDString()
NSLog("output is : %@", identifier)

Swift3

let identifier = UIDevice.current.identifierForVendor?.uuidString

NSLog("output is : %@", identifier! as String)

附加reference

Apple is apparently starting to remove access to the UDID (Unique Device IDentifier) in iOS5. In any event, the best you can now do for identification purposes is to use a UUID (Universally Unique IDentifier). This has to be on a per-app basis. That is, there is no way to identify the device any longer, but you can identify an app on a device.As long as the user doesn’t completely delete the app, then this identifier will persist between app launches, and at least let you identify the same user using a particular app on a device. Unfortunately, if the user completely deletes and then reinstalls the app then the ID will change, but this is the best anyone can do going forward.

关于ios - 以编程方式获取IOS设备的UDID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40418054/

相关文章:

html - CSS 视口(viewport)问题 : vh vs. 100%

ios - "[VKDefault] Tile in current unloaded state"iOS 11 map 不工作

ios - 如何在 Swift 中从 ConstUnsafePointer 创建 CStirng

iPhone - 自动提交 Appstore

iphone - MGTwittweEngine 没有获取推特页面提要

iphone - 如何恢复所有那些好的旧 Xcode 功能?

IOS : Correct way to reuse UIPanGestureRecognizer class/methods for multiple view?

ios - 如何从设备制作唯一标识符?

objective-c - 核心数据 : Using a temporary property for progress?

ios - 应用程序在启动时不断重新启动