How to preserve identifierForVendor in ios after uninstalling ios app on device?
You may keep it in KeyChain
-(NSString *)getUniqueDeviceIdentifierAsString{ NSString *appName=[[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey]; NSString *strApplicationUUID = [SSKeychain passwordForService:appName account:@"incoding"]; if (strApplicationUUID == nil) { strApplicationUUID = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; [SSKeychain setPassword:strApplicationUUID forService:appName account:@"incoding"]; } return strApplicationUUID;}
Generally, don't use identifierForVendor
. Instead, use NSUUID
to generate a custom UUID and store that in the keychain (because the keychain isn't deleted if the app is deleted and reinstalled).
Addition to @nerowolfe's answer.
SSKeychain uses kSecAttrSynchronizableAny
as a default synchronization mode. You probably don't want identifierForVendor
to be synced across multiple devices so here is a code:
// save identifierForVendor in keychain without syncNSError *error = nil;SSKeychainQuery *query = [[SSKeychainQuery alloc] init];query.service = @"your_service";query.account = @"your_account";query.password = [[[UIDevice currentDevice] identifierForVendor] UUIDString];query.synchronizationMode = SSKeychainQuerySynchronizationModeNo;[query save:&error];