I'm using [[UIDevice currentDevice] uniqueIdentifier]
in all of my apps, Apple is not allowing the use of uniqueIdentifier
anymore. I need something to use that replaces the uniqueIdentifier
which I can use to recognize a user even when the user deletes the app and installs it again, (and also get my app approved by apple).
我在我的所有应用程序中使用[[UIDevice currentDevice] uniqueIdentifier],Apple不再允许使用uniqueIdentifier。我需要使用一些东西替换uniqueIdentifier,即使用户删除应用程序并再次安装它,我也可以使用它来识别用户(并且还可以通过苹果批准我的应用程序)。
Thanks
3 个解决方案
#1
12
The documentation recommends what to do in this section.
文档建议在本节中执行的操作。
Special Considerations
Do not use the uniqueIdentifier property. To create a unique identifier specific to your app, you can call the CFUUIDCreate function to create a UUID, and write it to the defaults database using the NSUserDefaults class.特殊注意事项请勿使用uniqueIdentifier属性。要创建特定于应用程序的唯一标识符,可以调用CFUUIDCreate函数来创建UUID,并使用NSUserDefaults类将其写入默认数据库。
To make sure that the unique identifier remains after you delete the app you should store it in the keychain rather than NSUserDefaults. Using the keychain you will also be able to share the same unique ID across all of your apps on the same device using keychain access groups. This approach will prevent you from incorrectly tracking users after the device is no longer theirs, and it will be available on any new iDevice they restore from backup.
要确保在删除应用程序后仍保留唯一标识符,您应将其存储在钥匙串中而不是NSUserDefaults中。使用钥匙串,您还可以使用钥匙串访问组在同一设备上的所有应用程序之间共享相同的唯一ID。这种方法可以防止您在设备不再使用后错误地跟踪用户,并且可以在从备份恢复的任何新iDevice上使用它。
#2
3
Update for iOS 7 and prior:
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;
}
Device model you can receive through:
您可以通过以下途
+ (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;
}
#3
0
with digipeople's hack.
与digipeople的黑客。
Fix it to avoid app crash.
修复它以避免应用程序崩溃。
systemId = [[NSUUID UUID] UUIDstring];
systemId = [[NSUUID UUID] UUIDstring];
#1
12
The documentation recommends what to do in this section.
文档建议在本节中执行的操作。
Special Considerations
Do not use the uniqueIdentifier property. To create a unique identifier specific to your app, you can call the CFUUIDCreate function to create a UUID, and write it to the defaults database using the NSUserDefaults class.特殊注意事项请勿使用uniqueIdentifier属性。要创建特定于应用程序的唯一标识符,可以调用CFUUIDCreate函数来创建UUID,并使用NSUserDefaults类将其写入默认数据库。
To make sure that the unique identifier remains after you delete the app you should store it in the keychain rather than NSUserDefaults. Using the keychain you will also be able to share the same unique ID across all of your apps on the same device using keychain access groups. This approach will prevent you from incorrectly tracking users after the device is no longer theirs, and it will be available on any new iDevice they restore from backup.
要确保在删除应用程序后仍保留唯一标识符,您应将其存储在钥匙串中而不是NSUserDefaults中。使用钥匙串,您还可以使用钥匙串访问组在同一设备上的所有应用程序之间共享相同的唯一ID。这种方法可以防止您在设备不再使用后错误地跟踪用户,并且可以在从备份恢复的任何新iDevice上使用它。
#2
3
Update for iOS 7 and prior:
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;
}
Device model you can receive through:
您可以通过以下途
+ (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;
}
#3
0
with digipeople's hack.
与digipeople的黑客。
Fix it to avoid app crash.
修复它以避免应用程序崩溃。
systemId = [[NSUUID UUID] UUIDstring];
systemId = [[NSUUID UUID] UUIDstring];