iOS7 - Device unique identifier

furqan kamani picture furqan kamani · Sep 25, 2013 · Viewed 72.2k times · Source

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 same value every time.

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

In iOS 7, above method is retuning different values and we are getting issues in user identification. iOS 7 apis provide following alternate.

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

I replaced "uniqueIdentifier" with "identifierForVendor", and created Ad hoc build. Installed build on both iOS 7 and iOS 6 devices. In iOS 7, so far, i am getting same value every time, but iOS 6 gives different values every time, when we delete and reinstall app.

Currently application is not available on App store. So i am not sure how this api works for App store build.

Questions: 1) For appstore app, is "identifierForVendor" return same value for iOS 7 every time? or it may change when user delete and reinstall app in future? 2) Is any other alternative available for "unique identifier" in iOS 7 apis, which return same values for both iOS 6 and 7? 3) Any other suggestions...

Answer

Dima picture Dima · Sep 25, 2013

As you can see in the documentation here:

The value of this property is the same for apps that come from the same vendor running on the same device. A different value is returned for apps on the same device that come from different vendors, and for apps on different devices regardless of vendor.

The value of this property may be nil if the app is running in the background, before the user has unlocked the device the first time after the device has been restarted. If the value is nil, wait and get the value again later.

The value in this property remains the same while the app (or another app from the same vendor) is installed on the iOS device. The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them. Therefore, if your app stores the value of this property anywhere, you should gracefully handle situations where the identifier changes.

In short, the identifier for a particular vendor will remain the same if at least one app by that vendor remains on the device. Once there are no more apps left (or in the case of a single app, it is reinstalled), the identifier can and will change. As far as I know, there should not be a difference on iOS 6 vs iOS 7, so any difference you are seeing is coincidental.