2

I am developing app targeting from ios5 to ios7. The app requires a unique id across all the iDevices.

There are some ways to get it

  1. [[UIDevice currentDevice] uniqueIdentifier] It is depreciated in ios5

  2. [[UIDevice currentDevice] identifierForVendor] It is not available in ios5

  3. [NSUUID UUID] It is not available in ios5

  4. CFUUIDCreateString(NULL, CFUUIDCreate(NULL)) It creates a uuid which is compatible with all ios versions. But there is chance of getting same id for different devices(or users).(i dont want any two apps having same id).

  5. IMEI number. I came to know through google search that we cant get IMEI number through ios

So Is there any other option to get a unique id for ios Thanks in advance.

pradeep
  • 413
  • 2
  • 7
  • 20
  • yes the question is duplicate. but that question didn't solve my problem. Check my question and its answers. – pradeep Dec 08 '13 at 13:24

3 Answers3

3

There is a simple answer: It is not possible. Here you have an overview over the identifiers: The Developer’s Guide to Unique Identifiers

enter image description here

iCode
  • 1,456
  • 1
  • 15
  • 26
  • I checked it previously, but i want to know if there is any other way and how others are overcoming this type of problem – pradeep Dec 08 '13 at 13:18
3

CFUUIDCreateString() is the recommended way of generating a Unique ID to use in your apps.

CFUUID is, as its name suggests, a UUID, which does have a chance of being the same, but in your individual case that chance is so insurmountably small that it'll likely never happen. See here:

http://en.wikipedia.org/wiki/Universally_unique_identifier#Random_UUID_probability_of_duplicates

In other words, only after generating 1 billion UUIDs every second for the next 100 years, the probability of creating just one duplicate would be about 50%. The probability of one duplicate would be about 50% if every person on earth owns 600 million UUIDs.

I don't think your app is going to be installed by every person on earth 600 million times. :)

In order to persist the UUID, you can save it in the keychain which is only cleared on iOS when the device is reset completely (it will persist between OS upgrades, but not full OS restores).


You shouldn't be using a generated UUID to keep track of a user. What if that user gets a new phone and wants to continue using your app? How do you know it's the same user on a new device?

That's what a user account is for. If you truly need to track the user and not the device, then you need to create a user account and have it stored on your backend service. No amount of UUID fudging is going to keep track of a user between devices. So many things can happen that might lead to a new UUID being created:

  • user buys a new device
  • loses their old device
  • device gets damaged
  • restores the device to factory settings
  • sells the device to a someone else

If your answer to this is "we don't want to make an account for a user" then you obviously don't care that much about tracking them. UUIDs don't identify users. End of story.

Jasarien
  • 58,279
  • 31
  • 157
  • 188
  • That have another issue i.e. uninstalling and reinstalling the app creates new id – pradeep Dec 08 '13 at 13:46
  • @pradeep: Once created, you can save the uuid in the Keychain (as mentioned in one of the answers to the "possible duplicate"). Keychain entries are preserved even by uninstall/reinstall. – Martin R Dec 08 '13 at 14:44
  • @MartinR I will check that option. – pradeep Dec 08 '13 at 14:53
  • @Jasarien My requirement is not tracking the user. But restrict the device to only one user. Others must not use the app from that device until the registered user unregisters the device. – pradeep Dec 09 '13 at 05:09
  • Sounds to me like you'd still want a user account, then add a generated device UUID to the user's 'registered devices'. But I've said all I can. I hope you don't plan to release to the App Store with such a restriction, Apple certainly won't allow apps to restrict themselves to one device per user. – Jasarien Dec 09 '13 at 13:54
  • @Jasarien thanks for ur help. We are changing our backend because of above problems. – pradeep Dec 10 '13 at 07:18
0

If your app talks in someway to a backend, you can call this backend on first launch. Have the backend return a unique number (e.g. the index in a table) when the app does not already have this ID. This way, you can identify unique installs. Only caveat is that when a user un-installs the app you have an entry in your DB that is no longer active. Also, when this user re-installs this app is that this install will get a new number. I think this is as good as you can do.

Joride
  • 3,722
  • 18
  • 22
  • First thing is there is no way of sending unique id from backend (according to client req.). and the second thing is it has drawbacks which u said already. – pradeep Dec 08 '13 at 13:44
  • The client probably means 'don't have money for that'. :). But yeah, the drawbacks remain unsolved. I'm basically in the same boat and trying to live with the drawbacks. – Joride Dec 08 '13 at 13:46
  • The problem is when the user uninstalls and reinstalls it a new id is going to be generated, which shouldn't be happened.(since a new isntance is created for same user) – pradeep Dec 08 '13 at 13:51
  • Yes I know, unfortunately there is no way around this. I is the closest you can get to a UDID. – Joride Dec 08 '13 at 13:57
  • k thanks. But how other people are overcoming this drawback – pradeep Dec 08 '13 at 13:59
  • I don't know how others are overcoming this. One idea is to consider people that haven't contacted the back end in a long time as uninstalls. It is a pickle I know, but I have no clear cut fix... :( – Joride Dec 09 '13 at 16:55