关于objective c:以编程方式获取IOS设备的UDID?

get UDID of IOS device programmatically?

本问题已经有最佳答案,请猛点这里访问。

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

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

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


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

斯威夫特2 X(X denote。这里首先从2.0版本)P></

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

swift3P></

1
2
3
let identifier = UIDevice.current.identifierForVendor?.uuidString

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

额外的参考P></

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.