How to get unchanged device id from ios7 device programmatically

我只是一个虾纸丫 提交于 2019-12-03 08:46:37
Manab Kumar Mal

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];

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

Purushothaman

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!