16

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

        deviceName = [[UIDevice currentDevice]uniqueIdentifier];

但我收到警告 uniqueIdentifier 在 ios5 中已弃用。

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

4

4 回答 4

18

您可以使用以下代码

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 上有一个错误会报告“空”标识符 -更多信息

于 2012-09-26T14:23:18.887 回答
1

你不能再获得 UUID。禁止这样做,您的应用将被 Apple 拒绝。

于 2012-09-26T10:29:59.420 回答
1

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

于 2013-07-31T12:02:36.800 回答
0

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

但是,如果您想在用户升级手机时或在您的多个应用程序中(除非它们共享相同的 Bundle Seed ID)在您的应用程序中保留相同的标识符,请使用:https ://github.com/blackpixel/BPXLUUIDHandler

很有用!

于 2012-09-26T14:39:09.410 回答