How to generate Unique ID of device for iPhone/iPad using Objective-c

You can use UUID (Universal User Identification). Following link contains apple documentation

https://developer.apple.com/reference/uikit/uidevice/1620059-identifierforvendor

https://developer.apple.com/library/content/releasenotes/General/WhatsNewIniOS/Articles/iOS7.html#//apple_ref/doc/uid/TP40013162-SW1

you can use this code for UUID:

//Objective-C

NSString * string =  [[[UIDevice currentDevice] identifierForVendor] UUIDString];

//Swift

let deviceID = UIDevice.currentDevice().identifierForVendor?.UUIDString 

//Swift 3

let deviceID = UIDevice.current.identifierForVendor?.uuidString

Yes, UDID is deprecated; we are not allowed to get UDID due to user privacy purposes. Apple does not allow to get any identifiers that uniquely identifies a device, such as IMEI, MAC address, UDID etc.

UUID is the best way to go as of now. But that would be unique for each vendor. You are not assured that it will be unique each time you get the UUID string. Best bet is to store the UUID string to phone's Keychain and retrieve it when needed, with a catch. When you factory-reset your phone, the keychain items would be erased. This limitation should be kept in mind.


UPDATE - IN IOS 10.3 BETA'S:

It seems that Apple has made some changes to how Keychain works in iOS 10.3+. Keychain items stored in the Keychain will be deleted when the all the apps from the specific vendor are uninstalled. According to Apple, the residence of sensitive information of an app even after the app is gone from the device may lead to security risks, so they decided to forbid this kind of behavior.

Developers relying on Keychain storage even after an uninstall for their apps can make use of this WORKAROUND to continue with the intended functionality. According to this workaround, any app can access the information stored in that specific Keychain Access Group, so it is recommended that adding an extra layer of encryption to your data will protect it with even more security, although keychain encrypts items by default.


UPDATE - IOS 10.3.3 (STABLE): It seems that the keychain items deletion was a BUG in early betas of iOS 10.3.3 and was fixed later in the stable release. This might have been caused during betas since strange things can happen during that phase. It should be no problem to use Keychain hereafter.


Use the below code to get UDID for iOS device Use KeychainItemWrapper Class download from URL KeychainItemWrap

NSString *uuid;
KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"AC_APP_UUID" accessGroup:nil];
NSString *keychainUUID = [keychain objectForKey:(__bridge id)(kSecAttrAccount)];
NSString *appVersion = [NSString stringWithFormat:@"%@",@"1.0"];
[keychain setObject:appVersion forKey:(__bridge id)(kSecAttrDescription)];
if (keychainUUID==nil||[keychainUUID isKindOfClass:[NSNull class]]||keychainUUID.length==0) {
    uuid = [[NSUUID UUID] UUIDString];
    [keychain setObject:uuid forKey:(__bridge id)(kSecAttrAccount)];
}else{
    uuid = [keychain objectForKey:(__bridge id)(kSecAttrAccount)];
}