Always get a unique device id in iOS 7
Asked Answered
C

7

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.

Cozza answered 26/10, 2013 at 12:35 Comment(2)
are you testing on iOS< 6.1.3?Orion
my application supporting from ios 5.0 to ios 7.0 and right now i am testing in ios 7.0Cozza
P
30

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'

Pout answered 8/4, 2014 at 12:45 Comment(1)
When Reset content and settings on device, the returned string is different.Selfconfidence
M
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.

Mcmann answered 5/6, 2015 at 7:29 Comment(0)
H
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.

Hermy answered 26/10, 2013 at 12:44 Comment(3)
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.Cozza
No, it's not possible to get an identifier that is always the same. It's all there in the documentation.Hermy
This value will change if you delete all apps from that vendor and reinstall one.Nonfulfillment
R
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.

Rosa answered 26/10, 2013 at 12:46 Comment(0)
O
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.

Orion answered 26/10, 2013 at 12:44 Comment(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.Cozza
C
0

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

Christiansand answered 26/10, 2013 at 13:53 Comment(0)
M
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.

Merwyn answered 19/9, 2015 at 12:8 Comment(1)
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'.Drive

© 2022 - 2024 — McMap. All rights reserved.