The Advertisingidentifier and Identifierforvendor Return "00000000-0000-0000-0000-000000000000"

The advertisingIdentifier and identifierForVendor return 00000000-0000-0000-0000-000000000000

It appears to be a bug in iOS. Seeing the same issue on devices that have been upgraded over-the-air, but devices upgraded with Xcode or iTunes work as expected without zeros.

Tried similar steps as you, and the only common theme was over-the-air (bad) versus tethered upgrade (good).

Update: Users that move directly from iOS 5.1 to 6.1 over-the-air experience a different behavior. Every time the app is closed completely and restarted, a new value is being returned by identifierForVendor. This would be expected if the app was being uninstalled and reinstalled, but that's not the case.

How to use the identifierForVendor in ios5.?

You can use the following code

if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
// This will run if it is iOS6 or higher
return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
} else {
// This will run before iOS6 and you can use openUDID or other
// method to generate an identifier
}

And this way you can maintain the previous min requirement.

This identifier is unique for all the apps from one vendor. If you want unique identifier for device you need to use:

if (!NSClassFromString(@"ASIdentifierManager")) {
// This will run before iOS6 and you can use openUDID, per example...
return [OpenUDID value];
}
return [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];

Warning: There is a bug on iOS6 that reports "null" identifier if the device was updated "by air" - More info

CFUUID Vs. advertisingIdentifier Vs. identifierForVendor

  • identifierForVendor a unique identifier shared by all your apps on the user's device. If the user has more than one app made by you they will all share this identifier. This identifier will be reset if the user deletes all the apps by the same vendor.
  • advertisingIdentifier unique identifier that can be used to track use for advertising purposes. Can be reset by the the user.
  • CFUUID just a class that creates an UUID every time you call it.

The code you posted will create a new unique identifier every time it is called. You should store this identifier in NSUSerDefaults or Keychain and read it from there to build some kind of user tracking.

identifierForVendor and iOS6

You can use this:

NSString *udid;

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))
udid = [UIDevice currentDevice].identifierForVendor.UUIDString;
else
udid = [UIDevice currentDevice].uniqueIdentifier;

with pre processor code:

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

UIDevice uniqueIdentifier deprecated - What to do now?

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.

Edit 2: As was pointed out by others, the preferred solution since iOS 6 is -[UIDevice identifierForVendor]. In most cases, you should be able use it as a drop-in replacement to the old -[UIDevice uniqueIdentifier] (but a UUID that is created when the app starts for the first time is what Apple seems to want you to use).

Edit 3: So this major point doesn't get lost in the comment noise: do not use the MAC as UUID, create a hash using the MAC. That hash will always create the same result every time, even across reinstalls and apps (if the hashing is done in the same way). Anyways, nowadays (2013) this isn't necessary any more except if you need a "stable" device identifier on iOS < 6.0.

Edit 4: In iOS 7, Apple now always returns a fixed value when querying the MAC to specifically thwart the MAC as base for an ID scheme. So you now really should use -[UIDevice identifierForVendor] or create a per-install UUID.



Related Topics



Leave a reply



Submit