【发布时间】:2012-03-12 20:42:42
【问题描述】:
我在所有应用程序中都使用[[UIDevice currentDevice] uniqueIdentifier],Apple 不再允许使用uniqueIdentifier。
我需要使用一些东西来替换 uniqueIdentifier,即使用户删除了应用程序并再次安装它,我也可以使用它来识别用户,(并且让我的应用程序得到苹果的批准)。
谢谢
【问题讨论】:
标签: objective-c ios xcode
我在所有应用程序中都使用[[UIDevice currentDevice] uniqueIdentifier],Apple 不再允许使用uniqueIdentifier。
我需要使用一些东西来替换 uniqueIdentifier,即使用户删除了应用程序并再次安装它,我也可以使用它来识别用户,(并且让我的应用程序得到苹果的批准)。
谢谢
【问题讨论】:
标签: objective-c ios xcode
iOS 7 及更早版本的更新:
+ (NSString *)uniqueDeviceIdentifier
{
NSString *device_id = nil;
if ([[self deviceModel] isEqualToString:@"Simulator iOS"]) {
// static id for simulator
device_id = @"== your random id ==";
}
else if (CurrentIOSVersion >= 6.f) {
// iOS 6 and later
device_id = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
}
else {
// iOS 5 and prior
SEL udidSelector = NSSelectorFromString(@"uniqueIdentifier");
if ([[UIDevice currentDevice] respondsToSelector:udidSelector]) {
device_id = [[UIDevice currentDevice] performSelector:udidSelector];
}
}
NSLog(@">>>>>> device_id: %@", device_id);
return device_id;
}
您可以通过以下方式接收的设备型号:
+ (NSString*)deviceModel
{
static NSString *device_model = nil;
if (device_model != nil)
return device_model;
struct utsname systemInfo;
uname(&systemInfo);
NSString *str = @(systemInfo.machine);
return device_model;
}
【讨论】:
uniqueIdentifier 的替代品,它必须是持久的。
使用数字人的黑客。
修复它以避免应用崩溃。
systemId = [[NSUUID UUID] UUIDstring];
【讨论】:
documentation 推荐本节中的操作。
特殊注意事项
不要使用 uniqueIdentifier 属性。要创建特定于您的应用的唯一标识符,您可以 调用 CFUUIDCreate 函数创建一个 UUID,并将其写入 使用 NSUserDefaults 类的默认数据库。
为确保在您删除应用程序后唯一标识符仍然存在,您应该将其存储在 keychain 而不是 NSUserDefaults 中。使用钥匙串,您还可以使用keychain access groups 在同一设备上的所有应用程序之间共享相同的唯一 ID。这种方法可以防止您在设备不再属于用户后错误地跟踪用户,并且可以在他们从备份中恢复的任何新 iDevice 上使用。
【讨论】: