31

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

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

In iOS 7, the above method is returning different values and we are getting issues in user identification. iOS 7 provides the following alternate.

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

We replaced uniqueIdentifier with identifierForVendor, and created an Ad-hoc build. We then installed the build on both iOS 7 and iOS 6 devices. So far in iOS 7, we are getting the same value every time, but iOS 6 gives different values every time we delete and reinstall the app.

jaydev
  • 1,371
  • 5
  • 15
  • 27

7 Answers7

31

Use this little helper method to keep identifier in Keychain between install/delete sessions of app

-(NSString *)getUniqueDeviceIdentifierAsString
{
    NSString *appName=[[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey];

    NSString *strApplicationUUID = [SSKeychain passwordForService:appName account:@"incoding"];
    if (strApplicationUUID == nil)
    {
        strApplicationUUID  = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
        [SSKeychain setPassword:strApplicationUUID forService:appName account:@"incoding"];
    }

    return strApplicationUUID;
}

Add the SSKeychain library to your project, e.g. via Cocoapods with pod 'SSKeychain'

Stan James
  • 2,277
  • 26
  • 35
nerowolfe
  • 4,719
  • 3
  • 18
  • 19
8

What is UDID replaced with?

For now it looks like Apple plan to replace UDID’s with two different identifiers: Vendor IDs and Advertising IDs.

Vendor IDs

ID that is identical between apps from the same developer. Erased with removal of the last app for that Team ID.

Advertising IDs

Unique to the device. Available to all applications; used for advertising — iAd has converted from UDID for iOS 6 and later. Reset with “Erase All Content & Settings”.


For the most part, Vendor IDs will allow developers with multiple apps to identify you as the same user across all their apps. This can help developers understand their audience better and provide a better service.

Advertising IDs will still create a unique identifier for the device but unlike the UDID, this can be turned off or reset, just as cookies can be controlled in the browser on your desktop or laptop.

With the announcement of iOS7 earlier this week, Apple took an additional step, which was to turn off another unique identifier — the “MAC Address” that app developers and advertising companies could use instead of the new Advertising ID. By closing this loophole, Apple is taking the good step of forcing these companies to only use a cross-app identifier that users can control.

What remains to be seen is whether the targeting companies will continue to seek ways around Apple’s mandate. Other technologies, like “device fingerprinting,” have been developed to uniquely identify your device outside of Apple’s framework. Whether Apple will crack down on these methods remains to be seen.

Kyle Decot
  • 19,418
  • 35
  • 132
  • 245
K-__-T
  • 464
  • 5
  • 6
2

From the UIDevice Class reference for identifierForVendor:

The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them. The value can also when installing test builds using Xcode or when installing an app on a device using ad-hoc distribution. Therefore, if your app stores the value of this property anywhere, you should gracefully handle situations where the identifier changes.

neilco
  • 7,699
  • 2
  • 33
  • 41
  • 1
    ok thanks but i want to get always unique id. else is there any alternative way to do unique id always same just like as device identifier method. if it is posible then please suggest me. or it is posible by identifierforvander method. – jaydev Oct 26 '13 at 12:49
  • No, it's not possible to get an identifier that is always the same. It's all there in the documentation. – neilco Oct 26 '13 at 12:53
  • This value will change if you delete all apps from that vendor and reinstall one. – Alex Zavatone Jan 28 '16 at 20:28
2

Are there additional apps from the same vendor installed on iOS7 devices? According to the docs:

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. The value can also when installing test builds using Xcode or when installing an app on a device using ad-hoc distribution. Therefore, if your app stores the value of this property anywhere, you should gracefully handle situations where the identifier changes.

Do you provide the app via the AppStore? If not:

If the app was not installed from the app store (such as when the app is still in development), the vendor is determined based on the app’s bundle ID. The bundle ID is assumed to be in reverse-DNS format, and the first two components are used to generate a vendor ID. For example, com.example.app1 and com.example.app2 would appear to have the same vendor ID.

tilo
  • 13,266
  • 6
  • 62
  • 81
1

If there are no other applications signed by you installed on the device, it is ok for identifier for vendor to change. Also, identifier for vendor may change if you install you application through different distribution methods, ie. application may not have the same identifier for vendor when installed through XCode and when distributed via TestFlight or HockeyApp.

Maggie
  • 7,253
  • 6
  • 39
  • 65
  • ok thanks but i want to get always unique id. else is there any alternative way to do unique id always same just like as device identifier method. if it is posible then please suggest me. – jaydev Oct 26 '13 at 12:48
0

Try to clear caches of app on your machine and then check. It may be your cache problem

Hussain Shabbir
  • 13,963
  • 4
  • 34
  • 53
0

To add something to nerowolfe's answer, there is a great Keychain Wrapper named MCSMKeychainItem, that, on top of several other things, allows you to generate and retrieve Unique Device ID with single line of code:

[MCSMApplicationUUIDKeychainItem applicationUUID];

so the basic usage will be something like

+ (NSString *)deviceId {
  // load unique device ID or generate new one
  return [MCSMApplicationUUIDKeychainItem applicationUUID];
}

It works on the basis of Keychain, where it stores once-generated unique identifier (as nerowolf suggested). It's open-source and you can download it here on github.

Note: I am not the author of the extension, nor do I in any way know him/her.

Community
  • 1
  • 1
FurloSK
  • 411
  • 2
  • 14
  • A little side-note for those who are in need of a real device-specific unique id that does NOT change ever, 'the UUID will be deleted if the user restores their device, along with every other keychain item'. – Burak Feb 14 '17 at 15:45