@@ -35,6 +35,29 @@ of this software and associated documentation files (the "Software"), to deal
3535
3636@implementation OSPrivacyConsentController
3737
38+ + (void )migrate {
39+ [self migrateConsentGranted ];
40+ }
41+
42+ // / `GDPR_CONSENT_GRANTED` had previously been saved to the standard user defaults.
43+ // / However, this value is also read from the NSE (for example, to send confirmed deliveries).
44+ // / Migrate this value to the shared user defaults, if it exists.
45+ + (void )migrateConsentGranted {
46+ long consentGrantedCacheFixVersion = 50210 ;
47+ long sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey: OSUD_CACHED_SDK_VERSION_FOR_CORE defaultValue: 0 ];
48+
49+ if (sdkVersion >= consentGrantedCacheFixVersion) {
50+ return ;
51+ }
52+
53+ if ([OneSignalUserDefaults.initStandard keyExists: GDPR_CONSENT_GRANTED]) {
54+ [OneSignalLog onesignalLog: ONE_S_LL_DEBUG message: [NSString stringWithFormat: @" OSPrivacyConsentController migrating consent granted from version: %ld " , sdkVersion]];
55+ // The default value should never be used, however the getSavedBoolForKey method requires it
56+ BOOL granted = [OneSignalUserDefaults.initStandard getSavedBoolForKey: GDPR_CONSENT_GRANTED defaultValue: false ];
57+ [OneSignalUserDefaults.initShared saveBoolForKey: GDPR_CONSENT_GRANTED withValue: granted];
58+ }
59+ }
60+
3861+ (void )setRequiresPrivacyConsent : (BOOL )required {
3962 OSRemoteParamController *remoteParamController = [OSRemoteParamController sharedController ];
4063
@@ -56,13 +79,13 @@ + (BOOL)requiresUserPrivacyConsent {
5679 // if required and consent has not been previously granted, return false
5780 BOOL requiresConsent = [[[NSBundle mainBundle ] objectForInfoDictionaryKey: ONESIGNAL_REQUIRE_PRIVACY_CONSENT] boolValue ] ?: false ;
5881 if (requiresConsent || shouldRequireUserConsent)
59- return ![OneSignalUserDefaults.initStandard getSavedBoolForKey: GDPR_CONSENT_GRANTED defaultValue: false ];
82+ return ![OneSignalUserDefaults.initShared getSavedBoolForKey: GDPR_CONSENT_GRANTED defaultValue: false ];
6083
6184 return false ;
6285}
6386
6487+ (void )consentGranted : (BOOL )granted {
65- [OneSignalUserDefaults.initStandard saveBoolForKey: GDPR_CONSENT_GRANTED withValue: granted];
88+ [OneSignalUserDefaults.initShared saveBoolForKey: GDPR_CONSENT_GRANTED withValue: granted];
6689}
6790
6891+ (BOOL )shouldLogMissingPrivacyConsentErrorWithMethodName : (NSString *)methodName {
0 commit comments