Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get unchanged device id from ios7 device programmatically

Tags:

uuid

ios

ios7

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.

like image 535
Manab Kumar Mal Avatar asked Jan 28 '26 11:01

Manab Kumar Mal


1 Answers

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];
like image 195
Manab Kumar Mal Avatar answered Jan 31 '26 04:01

Manab Kumar Mal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!