Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Always get a unique device id in iOS 7

Our iOS application is for specific users. So, we used device unique identifier for user identification. This approach works fine till iOS 6, because we are getting the same value every time.

NSString *strUniqueIdentifier = [[UIDevice currentDevice] uniqueIdentifier]; 

In iOS 7, the above method is returning different values and we are getting issues in user identification. iOS 7 provides the following alternate.

NSUUID *oNSUUID = [[UIDevice currentDevice] identifierForVendor]; [strApplicationUUID setString:[oNSUUID UUIDString]]; 

We replaced uniqueIdentifier with identifierForVendor, and created an Ad-hoc build. We then installed the build on both iOS 7 and iOS 6 devices. So far in iOS 7, we are getting the same value every time, but iOS 6 gives different values every time we delete and reinstall the app.

like image 226
jaydev Avatar asked Oct 26 '13 12:10

jaydev


People also ask

Is device ID unique iOS?

Every iPhone, iPod touch and iPad has a unique identifier number associated with it, known as a UDID (Unique Device ID). Your UDID is a 40-digit sequence of letters and numbers that looks like this: 00000000-000000000000000.

Is iOS UUID unique?

A universally unique value to identify types, interfaces, and other items.

How can I get new device ID in iOS?

To generate a new device ID for iOS, you must factory reset your device. Go to Settings > General > Reset > Reset all Contents and Settings (the device will now effectively be restored to factory settings). Reinstall your app, open it and test the Push Pre-Permissions.


1 Answers

Use this little helper method to keep identifier in Keychain between install/delete sessions of app

-(NSString *)getUniqueDeviceIdentifierAsString {     NSString *appName=[[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey];      NSString *strApplicationUUID = [SSKeychain passwordForService:appName account:@"incoding"];     if (strApplicationUUID == nil)     {         strApplicationUUID  = [[[UIDevice currentDevice] identifierForVendor] UUIDString];         [SSKeychain setPassword:strApplicationUUID forService:appName account:@"incoding"];     }      return strApplicationUUID; } 

Add the SSKeychain library to your project, e.g. via Cocoapods with pod 'SSKeychain'

like image 80
nerowolfe Avatar answered Oct 10 '22 02:10

nerowolfe