New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/race condition after uninstalling app #383
Conversation
…efore crashing if it's removed.
…UserID had never been set, the app won't crash
Purchases/Caching/RCDeviceCache.m
Outdated
@@ -109,6 +112,7 @@ - (void)clearCachesForAppUserID:(NSString *)oldAppUserID andSaveNewUserID:(NSStr | |||
[self deleteAttributesIfSyncedForAppUserID:oldAppUserID]; | |||
|
|||
[self cacheAppUserID:newUserID]; | |||
self.appUserIDHasBeenSet = YES; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move this to cacheAppUserId? That way if another function calls that function, we won't forget to set this bool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, good call. don't know what I was thinking.
Purchases/Caching/RCDeviceCache.m
Outdated
@@ -99,7 +99,10 @@ - (nullable NSString *)cachedAppUserID { | |||
} | |||
|
|||
- (void)cacheAppUserID:(NSString *)appUserID { | |||
[self.userDefaults setObject:appUserID forKey:RCAppUserDefaultsKey]; | |||
@synchronized (self) { | |||
self.appUserIDHasBeenSet = YES; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to move this right after the set in the userDefaults
? Just in case it fails when calling setObject
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea! In practice, I don't think we're actually catching the error anywhere so it'd crash, but if we did add a try / catch this would lead to an inconsistent state.
Updated.
… when setting the object
Addresses #375
Fixes an issue where if the app modifies other userDefaults preferences, and the appUserID had never been set in RevenueCat, the SDK will crash.