get UDID of IOS device programmatically? [duplicate]

我的梦境 提交于 2019-11-26 13:59:32

问题


I want to get UDID of iOS device programmatically. I am using the following code to get UDID of iOS device.

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

But output I get is different from actual UDID of my device.


回答1:


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

Swift 2.X (HERE X DENOTE ABOVE ALL VERSION FROM 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)

additional 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.



来源:https://stackoverflow.com/questions/31652359/get-udid-of-ios-device-programmatically

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