4

In iOS 5 the usage of [[UIDevice currentDevice] uniqueIdentifier] got deprecated. We are now encouraged to use own-generated UUIDs and store them in the app's NSDefaults. That's OK for most usage, I guess.

But my question is - is it possible to generate somehow the UUID that would behave like the device ID right now - I would like to keep it the same even after the application is removed and reinstalled. The purpose of this is to help tracking possible fraud tries taken from the iPhone.

I'm wondering if usage of MAC-address, as with this category: https://github.com/erica/uidevice-extension/blob/master/UIDevice-Hardware.m would be OK?

kender
  • 85,663
  • 26
  • 103
  • 145
  • no of seconds since 1970 to current date should be unique no. if user is not playing with iPhone Time ;) – iOSPawan Nov 22 '11 at 12:25
  • but it's not bound to the specific device... and I need it to be non-changing. – kender Nov 22 '11 at 12:40
  • 1
    Unix time would be a poor choice for a unique ID since it isn't really unique at all. It might be adequate most of the time for most apps, but all it takes is for 2 users to launch the app for the first time at the same time for the system to fail. It also can't be persisted between removal and reinstallation, so it wouldn't be at all suitable. – Jonathan Ellis Nov 22 '11 at 16:50

2 Answers2

2

The discussion for the uniqueIdentifier property in the documentation states:

Do not use the uniqueIdentifier property. To create a unique identifier specific to your app, you can call the CFUUIDCreate function to create a UUID, and write it to the defaults database using the NSUserDefaults class.

Writing it to the user defaults should ensure that it is kept if the app is removed/reinstalled I would have thought.

Edit:

Sorry, they are not kept when an application is removed apparently. The documentation describes how to generate a UUID but I can't find out whether it is constant for a given user/device. I have seen some people proposing the use of keychain for persistence through app removal/re-installation but don't know how recommendable it is (and in any case the user can, I suppose, remove the entries).

Community
  • 1
  • 1
jbat100
  • 16,757
  • 4
  • 45
  • 70
0

Create your own UUID using the method described by Apple (the one pointed out by jbat), store it in NSUserDefaults.

Using iCloud you can then use the Key-value store to help 'persist' this UUID to a specific user, between installs and different devices.

JonB
  • 4,422
  • 2
  • 27
  • 25
  • 1
    I was thinking about that, but the problem is that the user can disable iCloud and its storage, and this can be done per-application, right? – kender Nov 22 '11 at 14:24
  • From what I can tell, you can't disable iCloud per application, but you can disable "Documents & Data" iCloud syncing, which in turn would cause the app not to be able to back up. – JonB Nov 22 '11 at 19:18