diff --git a/CountlyPersistency.m b/CountlyPersistency.m index 9fc02648..c5fe46ad 100644 --- a/CountlyPersistency.m +++ b/CountlyPersistency.m @@ -120,8 +120,14 @@ - (void)saveToFileSync - (NSString* )retrieveStoredDeviceID { - NSString* retrievedDeviceID = nil; + NSString* retrievedDeviceID = [NSUserDefaults.standardUserDefaults objectForKey:kCountlyStoredDeviceIDKey]; + if(retrievedDeviceID) + { + COUNTLY_LOG(@"Succesfully retrieved Device ID from UserDefaults: %@", retrievedDeviceID); + return retrievedDeviceID; + } + NSDictionary *keychainDict = @{ (__bridge id)kSecAttrAccount: kCountlyStoredDeviceIDKey, @@ -142,15 +148,24 @@ - (NSString* )retrieveStoredDeviceID if (data) { retrievedDeviceID = [NSString.alloc initWithData:data encoding:NSUTF8StringEncoding]; + + COUNTLY_LOG(@"Succesfully retrieved Device ID from KeyChain: %@", retrievedDeviceID); + + [NSUserDefaults.standardUserDefaults setObject:retrievedDeviceID forKey:kCountlyStoredDeviceIDKey]; + [NSUserDefaults.standardUserDefaults synchronize]; } } - COUNTLY_LOG(@"Retrieved Device ID: %@", retrievedDeviceID); + COUNTLY_LOG(@"Can not retrieve Device ID"); + return retrievedDeviceID; } - (void)storeDeviceID:(NSString *)deviceID { + [NSUserDefaults.standardUserDefaults setObject:deviceID forKey:kCountlyStoredDeviceIDKey]; + [NSUserDefaults.standardUserDefaults synchronize]; + NSDictionary *keychainDict = @{ (__bridge id)kSecAttrAccount: kCountlyStoredDeviceIDKey,