Skip to content

Commit

Permalink
Added userdefaults cache before keychain for device id persistency
Browse files Browse the repository at this point in the history
  • Loading branch information
erkanyildiz committed Jun 16, 2016
1 parent 4202088 commit b99a5c5
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions CountlyPersistency.m
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit b99a5c5

Please sign in to comment.