Wednesday, May 30, 2012

UIDevice uniqueIdentifier Deprecated - What To Do Now?


It has just come to light that the UIDevice uniqueIdentifier property is deprecated in iOS 5 and above. No alternative method or property appears to be available or forthcoming.



Many of our existing apps are tightly dependent on this property for uniquely identifying a particular device. Can anyone suggest any ideas how we might handle this problem going forward?



The suggestion from the documentation is...




Special Considerations



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.




... however this value won't be the same if a user uninstalls and re-installs the app.


Source: Tips4all

5 comments:

  1. A UUID created by CFUUIDCreate is unique if a user uninstalls and re-installs the app: you will get a new one each time.

    But you might want it to be not unique, i. e. it should stay the same when the user uninstalls and re-installs the app. This requires a bit of effort, since the most reliable per-device-identifier seems to be the MAC address. You could query the MAC and use that as UUID.

    Edit: One needs to always query the MAC of the same interface, of course. I guess the best bet is with en0. The MAC is always present, even if the interface has no IP/is down.

    ReplyDelete
  2. You can use your alternative for Apple UDID already. Kind guy gekitz wrote category on UIDevice which will generate some kind of UDID based on device mac-address and bundle identifier.

    You can find code on github

    ReplyDelete
  3. Based on the link proposed by @moonlight, i did several tests and it seems to be the best solution. As @DarkDust says the method goes to check en0 which is always available.
    There are 2 options:
    uniqueDeviceIdentifier (MD5 of MAC+CFBundleIdentifier)
    and uniqueGlobalDeviceIdentifier(MD5 of the MAC), these always returns the same values.
    Below the tests i've done (with the real device):

    #import "UIDevice+IdentifierAddition.h"

    NSLog(@"%@",[[UIDevice currentDevice] uniqueDeviceIdentifier]);
    NSLog(@"%@",[[UIDevice currentDevice] uniqueGlobalDeviceIdentifier]);



    XXXX21f1f19edff198e2a2356bf4XXXX - (WIFI)UDID
    XXXX7dc3c577446a2bcbd77935bdXXXX - (WIFI)GlobalAppUDID

    XXXX21f1f19edff198e2a2356bf4XXXX - (3G)UDID
    XXXX7dc3c577446a2bcbd77935bdXXXX - (3G)GlobalAppUDID

    XXXX21f1f19edff198e2a2356bf4XXXX - (GPRS)UDID
    XXXX7dc3c577446a2bcbd77935bdXXXX - (GPRS)GlobalAppUDID

    XXXX21f1f19edff198e2a2356bf4XXXX - (AirPlane mode)UDID
    XXXX7dc3c577446a2bcbd77935bdXXXX - (AirPlane mode)GlobalAppUDID

    XXXX21f1f19edff198e2a2356bf4XXXX - (Wi-Fi)after removing and
    reinstalling the app XXXX7dc3c577446a2bcbd77935bdXXXX (Wi-Fi) after
    removing and installing the app


    Hope it's useful.

    ReplyDelete
  4. check this out,

    we can use Keychain instead of NSUserDefaults class, to store UUID created by CFUUIDCreate.

    with this way we could avoid for UUID recreation with reinstallation,
    and obtain always same UUID for same application even user uninstall and reinstall again.

    UUID will recreated just when device reset by user.

    I tried this method with SFHFKeychainUtils and it's works like a charm.

    ReplyDelete
  5. You may want to consider using OpenUDID which is a drop-in replacement for the deprecated UDID.

    Basically, to match the UDID, the following features are required:


    unique or sufficiently unique (a low probability collision is
    probably very acceptable)
    persistence across reboots, restores, uninstalls
    available across apps of different vendors (useful to acquire users via CPI networks) -


    OpenUDID fulfills the above and even has a built-in Opt-Out mechanism for later consideration.

    Check http://OpenUDID.org it points to the corresponding GitHub.
    Hope this helps!

    As a side note, I would shy away from any MAC address alternative. While the MAC address appears like a tempting and universal solution, be sure that this low hanging fruit is poisoned. The MAC address is very sensitive, and Apple may very well deprecate access to this one before you can even say "SUBMIT THIS APP"... the MAC network address is used to authenticate certain devices on private lans (WLANs) or other virtual private networks (VPNs). .. it's even more sensitive than the former UDID!

    ReplyDelete