【问题标题】:How to use the identifierForVendor in ios5.?如何在ios5中使用identifierForVendor。?
【发布时间】:2012-09-26 10:28:15
【问题描述】:

我使用以下代码获取标识符

        deviceName = [[UIDevice currentDevice]uniqueIdentifier];

但我得到警告 uniqueIdentifier is deprecated in ios5.

那么如何在ios5中获取标识符值呢?

【问题讨论】:

标签: iphone ios5 ios6 uidevice


【解决方案1】:

您可以使用以下代码

if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
    // This will run if it is iOS6 or higher
    return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
} else {
   // This will run before iOS6 and you can use openUDID or other 
   // method to generate an identifier
}

这样你就可以保持之前的最低要求。

对于来自一个供应商的所有应用,此标识符是唯一的。如果您想要设备的唯一标识符,您需要使用:

if (!NSClassFromString(@"ASIdentifierManager")) {
    // This will run before iOS6 and you can use openUDID, per example...
    return [OpenUDID value];
}
return [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];

警告:iOS6 上存在一个错误,如果设备“通过空中”更新,则会报告“null”标识符 - More info

【讨论】:

    【解决方案2】:

    你不能再获得 UUID。禁止这样做,你的应用会被苹果拒绝。

    【讨论】:

    • 如何在 ios 6 中获取设备令牌任何想法
    【解决方案3】:

    在 ios 7 中你最好使用 [UIDevice identifierForVendor] 否则你会遇到麻烦,因为只会返回一个假 MAC。

    【讨论】:

      【解决方案4】:

      J.Costa 演示的方法是适用于 iOS 6 的好方法。

      但是,如果您希望在用户升级手机时或在您的多个应用中(除非它们共享相同的捆绑种子 ID)在您的应用中保持相同的标识符,请使用:https://github.com/blackpixel/BPXLUUIDHandler

      非常有用!

      【讨论】:

      • BPXLUUIDHandler 对return [[UIDevice currentDevice] uniqueIdentifier]; 的调用将在 iPhone 5 模拟器上失败(所以我不确定保护 TARGET_IPHONE_SIMULATOR 的原因是什么)。 BPXLUUIDHandler 缺少正确的密钥链常量.... UDID 可能会通过 iTunes 或 Apple 的云显示在 Mac 或 PC 上。开发者驱动的安全需求确实是坑。
      猜你喜欢
      • 2012-03-17
      • 2013-09-25
      • 1970-01-01
      • 1970-01-01
      • 2012-02-29
      • 1970-01-01
      • 2012-09-12
      • 1970-01-01
      相关资源
      最近更新 更多