方法 uniqueIdentifier]不再被允许,我需要一个替代
我在所有应用程序中使用[[UIDevice currentDevice] uniqueIdentifier]
,Apple不再允许使用uniqueIdentifier
。 我需要一些东西来替代uniqueIdentifier
,我可以使用它来识别用户,即使当用户删除了应用程序并重新安装它(并且也得到我的应用程序批准的苹果)。
谢谢
文档build议在本节中执行什么操作。
特别注意事项
不要使用uniqueIdentifier属性。 要创build特定于您的应用程序的唯一标识符,您可以调用CFUUIDCreate函数来创buildUUID,并使用NSUserDefaults类将其写入默认数据库。
为了确保在删除应用程序后保留唯一标识符,您应该将其存储在钥匙串中而不是NSUserDefaults中。 使用钥匙串,您还可以使用钥匙串访问组在同一设备上的所有应用程序中共享相同的唯一ID。 这种方法可以防止用户在设备不再使用后不正确地跟踪用户,并且可以在任何从备份恢复的新iDevice上使用。
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; }
用digipeople的黑客。
修复它,以避免应用程序崩溃。
systemId = [[NSUUID UUID] UUIDstring];