1.) Does Apple permit developers to retrieve the IMEI number and UDID of user device?
2.) How can I obtain these values programmatically?
3.) If Apple doesn\'t a
Apple no longer allows developers to obtain the UUID programmatically anymore. There are, however, workarounds that you can use to uniquely identify devices in your app. The code below allows you to create a unique identifier using CFUUIDCreate
.
Objective-C:
- (NSString*)GUIDString {
CFUUIDRef newUniqueID = CFUUIDCreate(kCFAllocatorDefault);
CFStringRef newUniqueIDString = CFUUIDCreateString(kCFAllocatorDefault, newUniqueID);
NSString *guid = (__bridge NSString *)newUniqueIDString;
CFRelease(newUniqueIDString);
CFRelease(newUniqueID);
return([guid lowercaseString]);
}
Swift:
func GUIDString() -> NSString {
let newUniqueID = CFUUIDCreate(kCFAllocatorDefault)
let newUniqueIDString = CFUUIDCreateString(kCFAllocatorDefault, newUniqueID);
let guid = newUniqueIDString as! NSString
return guid.lowercaseString
}
Once you have this unique identifier, you can store it in NSUserDefaults
, Core Data, send it up to a web service, etc, to associate this unique id with the device running your app. You can also use this as a class method on NSString
as seen here.