我一直在使用以下代码来获取标识符
deviceName = [[UIDevice currentDevice]uniqueIdentifier];
但是我收到了在iOS 5中已经被弃用的警告uniqueIdentifier。
那么在iOS 5中如何获取标识符的值呢?
你可以使用以下代码
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存在一个 bug,如果设备是通过空中更新的,则会报告“null”标识符 - 更多信息
您现在无法获取UUID。这是被禁止的行为,您的应用将会被苹果拒绝。
J.Costa演示的方法适用于iOS 6。
但是,如果您想在用户升级手机或在多个应用程序中保留相同的标识符(除非它们共享相同的Bundle Seed ID),请使用这个:https://github.com/blackpixel/BPXLUUIDHandler
非常有用!
return [[UIDevice currentDevice] uniqueIdentifier];
将在iPhone 5模拟器上失败(因此我不确定在TARGET_IPHONE_SIMULATOR上保护的原因是什么)。BPXLUUIDHandler缺少适当的钥匙串常量... UDID可能会通过iTunes在Mac或PC上显示,或者在Apple的云中。开发人员驱动的安全要求确实很糟糕。 - jww