The [[UIDevice currentDevice] uniqueIdentifier] method is no longer allowed, I need an alternative

I use [[UIDevice currentDevice] uniqueIdentifier] in all my applications, Apple no longer allows the use of uniqueIdentifier . I need to use something that replaces the uniqueIdentifier , which I can use to recognize the user, even when the user uninstalls the application and installs it again (and also gets my application approved by the apple).

thanks

+8
ios objective-c xcode
source share
3 answers

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 application, you can call the CFUUIDCreate function to create the UUID and write it to NSUserDefaults database by default.

To ensure that the unique unique identifier remains after the application is uninstalled, you should save it in keychain , not NSUserDefaults. Using the keychain, you can also use the same unique identifier in all your applications on the same device using key chain access groups . This approach will not allow you to incorrectly track users after the device is no longer theirs, and it will be available for any new iDevice that they restore from backup.

+12
source share

Update for iOS 7 and earlier:

 + (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; } 

The model of the device that you can get 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
source share
0
source share

All Articles