23

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...

rmaddy
  • 314,917
  • 42
  • 532
  • 579
furqan kamani
  • 721
  • 2
  • 7
  • 16

2 Answers2

30

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.

Dima
  • 23,484
  • 6
  • 56
  • 83
5

3) Any other suggestions...

You should consider strategies for identifying and authorizing the user instead of the device. Depending on a device-specific identifier prevents authorized users from switching devices without some sort of administrator interaction, and allows non-authorized users access if they happen to find/steal/borrow an authorized device. You can avoid these problems by relying on user credentials instead of device identifiers.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • 43
    He probably should, but this isn't an answer to the actual question, just a lecture... – Chad Robinson Oct 24 '14 at 13:37
  • @ChadRobinson OP asked for "any other suggestions," and as you can see from the quote, it's that part of the question that I answered. – Caleb Oct 24 '14 at 14:21
  • 2
    Ok but I think that your answer shouldn't be checked as the right one. – arniotaki Dec 15 '14 at 12:34
  • That's kind of missing the entire point, in't it? – user435779 Jun 09 '16 at 17:21
  • A valid use case is when you are already authenticating the user, and you want to distinguish which of the user's multiple devices you are using. You don't care about any details of the device, you just want to uniquely identify the device. – user435779 Jun 09 '16 at 17:24
  • @user435779 No, it's not missing the point at all. If all you want to do is distinguish between several devices owned by one user, just generate a UUID on your own and use that. Or, if your app relies on a server, the server can hand out identifiers. Or, you can ask the user to give each device a name. There are lots of possibilities, all of which fall under *other suggestions* because Apple decided several years ago to improve user security despite the inconvenience to app developers by removing access to the device ID. – Caleb Jun 09 '16 at 17:47