如何以编程方式从ios7设备获取未更改的设备ID [英] How to get unchanged device id from ios7 device programmatically

查看:165
本文介绍了如何以编程方式从ios7设备获取未更改的设备ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取唯一的设备ID来填充数据库中的唯一用户ID。我使用以下代码来获得它。

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

但是当我重新安装应用程序时,UUID一直在变化。但据我所知,设备ID永远不会改变。为此,我使用下面的代码与第三方 SSKeychain 来保存和检索旧的UDID:

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

现在的问题是该应用程序的版本发生了变化,即app v2。 0表单应用程序v1.0然后再次更改UDID。所以逻辑很清楚我没有得到唯一的UDID,我只是将UDID作为供应商或应用程序的基础。

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.

推荐答案

我已经通过 advertisingIdentifier

正如我在那里看到的那样,advertisingIdentifier是

As I have seen there that advertisingIdentifier is


一个字母数字字符串唯一对于每个设备,......

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

为此,我将它用作唯一标识符(尽管它用于$ b) $ b提供广告)。

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

我的代码是:

-(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;
}

只需在需要时调用它

[self UniqueAppId];

这篇关于如何以编程方式从ios7设备获取未更改的设备ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆