【问题标题】:Unique Identifier Changing on 64 bit iOS Device在 64 位 iOS 设备上更改唯一标识符
【发布时间】:2014-06-26 07:04:22
【问题描述】:

复习了很多问题,因为有很多问题具有相同的主题,但没有找到相同的问题,所以发布。

问题

希望为iOS 设备生成Unique Identifier,就像用户安装应用程序并重新安装一样生成相同的标识符。

已解决但不适用于 64 位设备

我使用此代码获取iOS 设备的唯一标识符,它工作正常,但是当我在64 bit iOS device 上运行它时,每次安装都会给出不同的结果。请查看是否有人知道可能的解决方案。

- (NSString *)GetUUID {
    @try {
        UIDevice *device = [UIDevice currentDevice];
        return [[device identifierForVendor]UUIDString];
    }
    @catch (NSException *exception) {
        return @"00000-00000-0000-00000";
    }
}

【问题讨论】:

  • 亲爱的,投反对票的人请评论投反对票的原因,因为这将有助于大家改进问题和答案。

标签: ios iphone uniqueidentifier uidevice


【解决方案1】:

只要设备上安装了来自同一开发者(供应商)的应用程序,identifierForVendor 将保持不变。

因此,如果用户卸载了您的应用并且用户设备上没有您的其他应用,则当用户重新安装您的应用时,identifierForVendor 将有所不同。

Apple 已经明确表示,他们不希望开发人员跟踪设备或每台设备的安装情况。因此,您无法再从设备中获取任何唯一标识符。

identifierForVendor 的更改可能与重新安装问题有关。我一直在跟踪identifierForVendor 并没有看到这个问题。

【讨论】:

  • 如果在同一设备上重新安装应用程序,我想获得相同的标识符,那么可行的解决方案是什么。
【解决方案2】:

为了在重新安装之间存储标识符,您可以使用此代码(将 SSKeychain 添加到项目中)

/*
 The following method determines the AppName and a uniqueidentifier and store it in the   keychain
 As a result when the user removes the app, downloads it again his JID and password which  are derived from the
 uniqueidentifier don't change.
 otherwide the identifierForVendor method would return a new value on reinstall
*/
-(NSString *)getUniqueDeviceIdentifierAsString
{

NSString *appName=[[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey];

NSString *strApplicationUUID = [SSKeychain passwordForService:appName account:@"incoding"];
if (strApplicationUUID == nil)
{
    strApplicationUUID  = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    [SSKeychain setPassword:strApplicationUUID forService:appName account:@"incoding"];
}

return strApplicationUUID;
}

【讨论】:

  • 感谢回复因为我直到现在才尝试过这个功能所以只是确认?
  • 是的,第一次安装后,此方法将在钥匙串中保留一个值。然后会检索这个值
【解决方案3】:

使用keychain Access解决获取不同的vendor ID

简单的 iPhone 钥匙串访问

http://useyourloaf.com/blog/2010/03/29/simple-iphone-keychain-access.html

【讨论】:

    猜你喜欢
    • 2013-09-19
    • 2014-04-05
    • 1970-01-01
    • 2013-10-07
    • 2019-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-13
    相关资源
    最近更新 更多