14

Is there is a alternative for UDID. My app will not be going to App Store as i'm using enterprise distribution. So is there any replacement. I tied advertising identifier, open udid, UIID and secure UDID. But if the phone is reset then i will get a new UDID. Any help would be appreciated.

Raptor
  • 53,206
  • 45
  • 230
  • 366
Avinash
  • 823
  • 1
  • 7
  • 18
  • try for device token. – Tendulkar Sep 18 '13 at 09:33
  • @Tendulkar it changes when the device is wiped or contents of the device is erased. – Avinash Sep 21 '13 at 11:39
  • you can't create UDID in iOS 7 check here in apple documentation https://developer.apple.com/library/ios/documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/occ/instp/UIDevice/identifierForVendor – Sandeep Khade Oct 11 '13 at 06:14
  • @user2739931: Did you find out the solution? – Nam Vu Dec 14 '13 at 05:53
  • @user2739931 I would be also interested as i need to identify which smartphone is accessing my enterprise app – noircc Dec 19 '13 at 16:06
  • @ZuzooVn Advertising identifier is best alternative for UDID. Negative is that if the user reset his settings which is ver unlikely it is the best alternative. – Avinash Feb 01 '14 at 09:54
  • var identifierForVendor: NSUUID! { get }: 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 change 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. – King-Wizard Nov 30 '14 at 23:53

7 Answers7

16

For above 6.0 iOS you can use identifierForVendor Or CFUUIDRef.

-(NSString*)uniqID
{
    NSString* uniqueIdentifier = nil;
    if( [UIDevice instancesRespondToSelector:@selector(identifierForVendor)] ) {
        // iOS 6+
        uniqueIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    } else {
        // before iOS 6, so just generate an identifier and store it
        uniqueIdentifier = [[NSUserDefaults standardUserDefaults] objectForKey:@"identifierForVendor"];
        if( !uniqueIdentifier ) {
            CFUUIDRef uuid = CFUUIDCreate(NULL);
            uniqueIdentifier = ( NSString*)CFUUIDCreateString(NULL, uuid);
            CFRelease(uuid);
            [[NSUserDefaults standardUserDefaults] setObject:uniqueIdentifier forKey:@"identifierForVendor"];
        }
    }
return uniqueIdentifier;
}//

UPDATE

As Leon Lucardie comment he is right

identifierForVendor will change after app uninstall/reinstall. See here 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.

Hemang
  • 26,840
  • 19
  • 119
  • 186
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
  • 7
    `identifierForVendor` will change after app uninstall/reinstall. See [here](https://developer.apple.com/library/ios/documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/occ/instp/UIDevice/identifierForVendor) `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.` – Leon Lucardie Sep 18 '13 at 09:42
  • using above code this working for me that's why i put this as an answer and i also test it in to device after uninstall/reinstall. – Nitin Gohel Sep 18 '13 at 09:43
  • It could work, but only if you have other apps from the same vendor to keep the identifier stored on the device. If the user only has one app from a certain vendor, the identifier will change after a reinstall. Considering in most situations the latter is the case, it's not a very reliable replacement for UDID – Leon Lucardie Sep 18 '13 at 09:45
  • @all Advertising Identifier will remain the same even when the app is uninstalled and re installed. But i will loose it when the phone contents are erased. Even with UIID its the same. Any other suggestion? or is there no alternative for this problem. I even tried Mac Address and it also has been removed in IOS7 – Avinash Sep 21 '13 at 11:30
  • @all Advertising Identifier will remain the same even when the app is uninstalled and re installed. But i will loose it when the phone contents are erased. Even with UIID its the same. Any other suggestion? or is there no alternative for this problem. I even tried Mac Address and it also has been removed in IOS7 – Avinash Sep 21 '13 at 11:34
  • @Nitin you could store uniqueIdentifier in keychain instead of user defaults. – fyasar Oct 28 '13 at 12:14
  • My extension in this library supports 3 levels of persistence: https://github.com/sentryco/Telemetry/blob/main/Sources/Telemetry/util/Identity.swift – Sentry.co Jun 18 '23 at 10:33
3

You have to create vendor id then save it using keychain and get it back once you reset your phone using date time

check this link UUID and UDID for iOS7

Community
  • 1
  • 1
Sandeep Khade
  • 2,832
  • 3
  • 21
  • 37
3

After trying all possible replacements. Advertising identifier is the best way to go. It remains same even after phone reset when i tested. If the user turn it off in the settings then we get a null value. Except for this hitch, this is the best replacement so far. Will update if i find any other better replacements.

Avinash
  • 823
  • 1
  • 7
  • 18
  • 2
    wrong decision, apple will reject your app. you may not use the advertising identifier for this purpose it is only allowed to be used for advertisement serving purpose. – Saurabh Passolia May 02 '14 at 10:07
  • 1
    I have already mentioned i'm going for enterprise distribution in the question part – Avinash May 05 '14 at 05:39
2

Easy, Just use this code:

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

As you can understand, if you plan to support iOS 5 then you should use OpenUDID (Apple restrict reading the UDID even on iOS 5). With some answers here you would simply get rejected by Apple (my code has been approved in several apps of mine).

Pay attention that identifierForVendor would change if your user would remove the app (or all vendor apps if there are several) and reinstall.

Idan
  • 9,880
  • 10
  • 47
  • 76
  • @all Advertising Identifier will remain the same even when the app is uninstalled and re installed. But i will loose it when the phone contents are erased. Even with UIID its the same. Any other suggestion? or is there no alternative for this problem. I even tried Mac Address and it also has been removed in IOS7 – Avinash Sep 21 '13 at 11:32
1

I use the combination APNS token and vendorId. Both are checked to verify cellphone identity and I update them accordingly in cellphone and server when one of those change.

It´s still possible that both change, when the app is uninstalled and/or reset and stored for a few months, then both values would change.

This will cause that next time the cellphone gets the app installed, it will be identified as a new one.

Additional to this I run a process in server that marks as deleted any device which hadn't connected to the server for two months.

In that case user authentication is required and cellphone is added again to the customer's pool of devices.

I have only one app yet, but once I have the second one I might include advertisingId.

Haac74
  • 568
  • 7
  • 9
0

These blog posts by Ole should be helpful:

iOS 5: http://oleb.net/blog/2011/09/how-to-replace-the-udid/ iOS 6+: http://oleb.net/blog/2012/09/udid-apis-in-ios-6/

Berk
  • 367
  • 2
  • 7
  • @all Advertising Identifier will remain the same even when the app is uninstalled and re installed. But i will loose it when the phone contents are erased. Even with UIID its the same. Any other suggestion? or is there no alternative for this problem. I even tried Mac Address and it also has been removed in IOS7 – Avinash Sep 21 '13 at 11:35
0

You can use after ios 6+ with Swift 2.2 version.

var uniqueIdentifier: NSString!
uniqueIdentifier = UIDevice.currentDevice().identifierForVendor?.UUIDString
Shah Nilay
  • 778
  • 3
  • 21