From b99a5c5bdce4639aa22e17cbfc80f03b2c3bede1 Mon Sep 17 00:00:00 2001 From: erkanyildiz Date: Thu, 16 Jun 2016 18:44:31 +0900 Subject: [PATCH] Added userdefaults cache before keychain for device id persistency --- CountlyPersistency.m | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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,