以编程方式获取 IOS 设备的 UDID?
get UDID of IOS device programmatically?
我想以编程方式获取 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 设备的 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.