3

I need to get the unique device id to populate unique user id in the database. I have used the following code to get that.

NSString *strApplicationUUID= [[[UIDevice currentDevice] identifierForVendor] UUIDString];

But when I am reinstalling the app, the UUID is changing all the time. But as far as I know the device id never changes. For that I used below code with the third party SSKeychain to save and retrieve the old UDID:

NSString *Appname = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
    NSString *strApplicationUUID = [SSKeychain passwordForService:Appname account:@"manab"];
    if (strApplicationUUID == nil)
    {
        strApplicationUUID  = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
        [SSKeychain setPassword:strApplicationUUID forService:Appname account:@"manab"];
    }

Now the problem is when the version of that Application is changed i.e app v2.0 form app v1.0 then again the UDID changed. So the logic is clear to me that I am not getting the unique UDID all the time, I am just getting UDID as vendor or App basis.

How to get that by programatically? Is there any other way to get that, please show me the right Direction.

embert
  • 7,336
  • 10
  • 49
  • 78
Manab Kumar Mal
  • 20,788
  • 5
  • 31
  • 43
  • You should read that article to get some information about UDIDs http://blog.appsfire.com/udid-is-dead-openudid-is-deprecated-long-live-advertisingidentifier/ – MP23 Feb 15 '14 at 09:38
  • UDID is no longer available in iOS 7 (and Apple have been telling developers it was deprecated since iOS 5). `identifierForVendor` is reset if a user uninstalls all of the apps from a vendor and then re-installs them. If you need to uniquely identify a user you need to use a user name and password. – Robotic Cat Feb 15 '14 at 10:40
  • Hi Robotic Cat, Can you please tell me If any one need to identify his device, then how can he do that, there must be an valid way as was ... – Manab Kumar Mal Feb 15 '14 at 10:58
  • Great Question. I have same issue Bro. – Jagat Dave Sep 28 '16 at 10:01

3 Answers3

6

I have solved this by using advertisingIdentifier.

As I have seen there that advertisingIdentifier is

"An alphanumeric string unique to each device, ..."

For that I have used it as the unique identifier (though it is used for the serving advertisements).

My code is:

-(NSString*)UniqueAppId
{
    NSString *Appname = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
    NSString *strApplicationUUID = [SSKeychain passwordForService:Appname account:@"manab"];
    if (strApplicationUUID == nil)
    {
        strApplicationUUID  = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
        [SSKeychain setPassword:strApplicationUUID forService:Appname account:@"manab"];
    }
    return strApplicationUUID;
}

and just calling it when needed as

[self UniqueAppId];
Jagat Dave
  • 1,643
  • 3
  • 23
  • 30
Manab Kumar Mal
  • 20,788
  • 5
  • 31
  • 43
  • 2
    Hi manab ... AdvertisingIdentifer is unique i agree with that .. but if you are using AdvertisingIdentifer and you are not showing any iAD or iAD is not loading properly Apple will reject your app – MANCHIKANTI KRISHNAKISHORE Jan 09 '15 at 06:22
1

advertisingIdentifier is a good option as it does not changed on application update or re-install.

But it also get changed when users reset their device so you may want to reconsider it based on your requirement.

For ref.

How to get the UDID in iOS 6 and iOS 7

CFUUID Vs. advertisingIdentifier Vs. identifierForVendor

In my case I preferred to use user's email address as a unique Id. So user will not get his data or identify on system only if user himself change his unique identity. :-)

Regards

Community
  • 1
  • 1
0

In Objective-c

if u want to get the unique id in IOS 7 and above the following is to be used:

first of all create your own unique ID and the you have to save in the keychain. Now use the vendor ID, it will be reset if all the apps by the same vendor are removed from the device.

Community
  • 1
  • 1
Purushothaman
  • 358
  • 4
  • 22