Skip to content

Commit 94f471e

Browse files
authored
Merge pull request #1541 from OneSignal/fix_privacy_consent_blocks_confirmed_deliveries
Fix requiring privacy consent blocks confirmed deliveries indefinitely
2 parents a1eea2b + 6054ff7 commit 94f471e

File tree

10 files changed

+76
-55
lines changed

10 files changed

+76
-55
lines changed

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OSPrivacyConsentController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ THE SOFTWARE.
2727

2828

2929
@interface OSPrivacyConsentController : NSObject
30+
+ (void)migrate;
3031
+ (BOOL)requiresUserPrivacyConsent;
3132
+ (void)consentGranted:(BOOL)granted;
32-
+ (BOOL)getPrivacyConsent;
3333
+ (BOOL)shouldLogMissingPrivacyConsentErrorWithMethodName:(NSString *)methodName;
3434
+ (void)setRequiresPrivacyConsent:(BOOL)required;
3535
@end

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OSPrivacyConsentController.m

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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,19 +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];
66-
}
67-
68-
+ (BOOL)getPrivacyConsent {
69-
// The default is the inverse of privacy consent required
70-
BOOL defaultValue = ![OneSignalUserDefaults.initShared getSavedBoolForKey:OSUD_REQUIRES_USER_PRIVACY_CONSENT defaultValue:NO];
71-
return [OneSignalUserDefaults.initStandard getSavedBoolForKey:GDPR_CONSENT_GRANTED defaultValue:defaultValue];
88+
[OneSignalUserDefaults.initShared saveBoolForKey:GDPR_CONSENT_GRANTED withValue:granted];
7289
}
7390

7491
+ (BOOL)shouldLogMissingPrivacyConsentErrorWithMethodName:(NSString *)methodName {

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCommonDefines.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,15 @@
9696
#define OSUD_CACHED_RECEIVED_IAM_IDS @"OSUD_CACHED_RECEIVED_IAM_IDS"
9797
#define OSUD_CACHED_UNATTRIBUTED_UNIQUE_OUTCOME_EVENTS_SENT @"CACHED_UNATTRIBUTED_UNIQUE_OUTCOME_EVENTS_SENT" // * OSUD_CACHED_UNATTRIBUTED_UNIQUE_OUTCOME_EVENTS_SENT
9898
#define OSUD_CACHED_ATTRIBUTED_UNIQUE_OUTCOME_EVENT_NOTIFICATION_IDS_SENT @"CACHED_ATTRIBUTED_UNIQUE_OUTCOME_EVENT_NOTIFICATION_IDS_SENT" // * OSUD_CACHED_ATTRIBUTED_UNIQUE_OUTCOME_EVENT_NOTIFICATION_IDS_SENT
99+
99100
// Migration
100-
#define OSUD_CACHED_SDK_VERSION @"OSUD_CACHED_SDK_VERSION"
101+
/// Value used by all modules prior to 5.2.10
102+
#define OSUD_LEGACY_CACHED_SDK_VERSION_FOR_MIGRATION @"OSUD_CACHED_SDK_VERSION"
103+
/// Values added in 5.2.10 for each module to own its own migration
104+
#define OSUD_CACHED_SDK_VERSION_FOR_CORE @"OSUD_CACHED_SDK_VERSION_FOR_CORE"
105+
#define OSUD_CACHED_SDK_VERSION_FOR_OUTCOMES @"OSUD_CACHED_SDK_VERSION_FOR_OUTCOMES"
106+
#define OSUD_CACHED_SDK_VERSION_FOR_IAM @"OSUD_CACHED_SDK_VERSION_FOR_IAM"
107+
101108
// Time Tracking
102109
#define OSUD_APP_LAST_CLOSED_TIME @"GT_LAST_CLOSED_TIME" // * OSUD_APP_LAST_CLOSED_TIME
103110
#define OSUD_UNSENT_ACTIVE_TIME @"GT_UNSENT_ACTIVE_TIME" // * OSUD_UNSENT_ACTIVE_TIME

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
// TODO: Testing: Should this class be defined in this file?
6363
@interface OneSignalCoreImpl : NSObject
6464

65+
+ (void)migrate;
6566
+ (void)setSharedClient:(nonnull id<IOneSignalClient>)client;
6667
+ (nonnull id<IOneSignalClient>)sharedClient;
6768

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCore.m

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,35 @@
3030

3131
@implementation OneSignalCoreImpl
3232

33+
+ (void)migrate {
34+
[self migrateCachedSdkVersion];
35+
[OSPrivacyConsentController migrate];
36+
[self saveCurrentSDKVersion];
37+
}
38+
39+
/// Every module should be responsible for its own migration, as it is possible for one module
40+
/// to finish migrating without another undergoing migration yet.
41+
/// See https://github.com/OneSignal/OneSignal-iOS-SDK/pull/1541
42+
+ (void)migrateCachedSdkVersion {
43+
if (![OneSignalUserDefaults.initShared keyExists:OSUD_LEGACY_CACHED_SDK_VERSION_FOR_MIGRATION]) {
44+
return;
45+
}
46+
47+
// The default value should never be used, however the getSavedIntegerForKey method requires it
48+
long sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey:OSUD_LEGACY_CACHED_SDK_VERSION_FOR_MIGRATION defaultValue:0];
49+
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"OneSignalCoreImpl migrating cached SDK versions from version: %ld", sdkVersion]];
50+
51+
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_CORE withValue:sdkVersion];
52+
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_OUTCOMES withValue:sdkVersion];
53+
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_IAM withValue:sdkVersion];
54+
[OneSignalUserDefaults.initShared removeValueForKey:OSUD_LEGACY_CACHED_SDK_VERSION_FOR_MIGRATION];
55+
}
56+
57+
+ (void)saveCurrentSDKVersion {
58+
int currentVersion = [ONESIGNAL_VERSION intValue];
59+
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_CORE withValue:currentVersion];
60+
}
61+
3362
static id<IOneSignalClient> _sharedClient;
3463
+ (id<IOneSignalClient>)sharedClient {
3564
if (!_sharedClient) {

iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalNotificationServiceExtensionHandler.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ + (void)addActionButtonsToExtentionRequest:(UNNotificationRequest*)request
132132
+ (void)onNotificationReceived:(NSString *)receivedNotificationId withBlockingTask:(dispatch_semaphore_t)semaphore {
133133
if (receivedNotificationId && ![receivedNotificationId isEqualToString:@""]) {
134134
// If update was made without app being initialized/launched before -> migrate
135+
[OneSignalCoreImpl migrate];
135136
[OSOutcomes migrate];
136137
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"NSE request received, sessionManager: %@", [OSSessionManager sharedSessionManager]]];
137138
// Save received notification id

iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSInAppMessageMigrationController.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ @implementation OSInAppMessageMigrationController
3434
+(void)migrate {
3535
[self migrateIAMRedisplayCache];
3636
[self migrateToOSInAppMessageInternal];
37+
[self saveCurrentSDKVersion];
3738
}
3839

3940
// Devices could potentially have bad data in the OS_IAM_REDISPLAY_DICTIONARY
4041
// that was saved as a dictionary and not CodeableData. Try to detect if that is the case
4142
// and save it is as CodeableData instead.
4243
+ (void)migrateIAMRedisplayCache {
4344
let iamRedisplayCacheFixVersion = 30203;
44-
long sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey:OSUD_CACHED_SDK_VERSION defaultValue:0];
45+
long sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_IAM defaultValue:0];
4546
if (sdkVersion >= iamRedisplayCacheFixVersion)
4647
return;
4748

@@ -71,7 +72,7 @@ + (void)migrateIAMRedisplayCache {
7172
// We must set the new class name to the unarchiver to avoid crashing
7273
+ (void)migrateToOSInAppMessageInternal {
7374
let nameChangeVersion = 30700;
74-
long sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey:OSUD_CACHED_SDK_VERSION defaultValue:0];
75+
long sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_IAM defaultValue:0];
7576
[NSKeyedUnarchiver setClass:[OSInAppMessageInternal class] forClassName:@"OSInAppMessage"];
7677
if (sdkVersion < nameChangeVersion) {
7778
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"Migrating OSInAppMessage from version: %ld", sdkVersion]];
@@ -88,5 +89,9 @@ + (void)migrateToOSInAppMessageInternal {
8889
}
8990
}
9091

92+
+ (void)saveCurrentSDKVersion {
93+
int currentVersion = [ONESIGNAL_VERSION intValue];
94+
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_IAM withValue:currentVersion];
95+
}
9196

9297
@end

iOS_SDK/OneSignalSDK/OneSignalOutcomes/OSOutcomes.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ + (void)migrate {
6060
+ (void)migrateToVersion_02_14_00_AndGreater {
6161
let influenceVersion = 21400;
6262
let uniqueCacheOutcomeVersion = 21403;
63-
long sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey:OSUD_CACHED_SDK_VERSION defaultValue:0];
63+
long sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_OUTCOMES defaultValue:0];
6464
if (sdkVersion < influenceVersion) {
6565
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"Migrating OSIndirectNotification from version: %ld", sdkVersion]];
6666

@@ -85,7 +85,7 @@ + (void)migrateToVersion_02_14_00_AndGreater {
8585
}
8686
+ (void)saveCurrentSDKVersion {
8787
let currentVersion = [ONESIGNAL_VERSION intValue];
88-
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION withValue:currentVersion];
88+
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_OUTCOMES withValue:currentVersion];
8989
}
9090

9191
#pragma mark Session namespace

iOS_SDK/OneSignalSDK/Source/OSMigrationController.m

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,47 +40,12 @@ + (OSOutcomeEventsCache *)outcomeEventsCache;
4040
@implementation OSMigrationController
4141

4242
- (void)migrate {
43-
[self migrateToVersion_02_14_00_AndGreater];
43+
[OneSignalCoreImpl migrate];
44+
[OSOutcomes migrate];
4445
let oneSignalInAppMessages = NSClassFromString(ONE_SIGNAL_IN_APP_MESSAGES_CLASS_NAME);
4546
if (oneSignalInAppMessages != nil && [oneSignalInAppMessages respondsToSelector:@selector(migrate)]) {
4647
[oneSignalInAppMessages performSelector:@selector(migrate)];
4748
}
48-
[self saveCurrentSDKVersion];
49-
}
50-
51-
/**
52-
* Support renaming of decodable classes for cached data
53-
*/
54-
- (void)migrateToVersion_02_14_00_AndGreater {
55-
let influenceVersion = 21400;
56-
let uniqueCacheOutcomeVersion = 21403;
57-
long sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey:OSUD_CACHED_SDK_VERSION defaultValue:0];
58-
if (sdkVersion < influenceVersion) {
59-
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"Migrating OSIndirectNotification from version: %ld", sdkVersion]];
60-
61-
[NSKeyedUnarchiver setClass:[OSIndirectInfluence class] forClassName:@"OSIndirectNotification"];
62-
NSArray<OSIndirectInfluence *> * indirectInfluenceData = [[OSInfluenceDataRepository sharedInfluenceDataRepository] lastNotificationsReceivedData];
63-
if (indirectInfluenceData) {
64-
[NSKeyedArchiver setClassName:@"OSIndirectInfluence" forClass:[OSIndirectInfluence class]];
65-
[[OSInfluenceDataRepository sharedInfluenceDataRepository] saveNotifications:indirectInfluenceData];
66-
}
67-
}
68-
69-
if (sdkVersion < uniqueCacheOutcomeVersion) {
70-
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"Migrating OSUniqueOutcomeNotification from version: %ld", sdkVersion]];
71-
72-
[NSKeyedUnarchiver setClass:[OSCachedUniqueOutcome class] forClassName:@"OSUniqueOutcomeNotification"];
73-
NSArray<OSCachedUniqueOutcome *> * attributedCacheUniqueOutcomeEvents = [[OSOutcomeEventsCache sharedOutcomeEventsCache] getAttributedUniqueOutcomeEventSent];
74-
if (attributedCacheUniqueOutcomeEvents) {
75-
[NSKeyedArchiver setClassName:@"OSCachedUniqueOutcome" forClass:[OSCachedUniqueOutcome class]];
76-
[[OSOutcomeEventsCache sharedOutcomeEventsCache] saveAttributedUniqueOutcomeEventNotificationIds:attributedCacheUniqueOutcomeEvents];
77-
}
78-
}
79-
}
80-
81-
- (void)saveCurrentSDKVersion {
82-
let currentVersion = [[OneSignal sdkVersionRaw] intValue];
83-
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION withValue:currentVersion];
8449
}
8550

8651
@end

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,10 +605,6 @@ + (void)setConsentGiven:(BOOL)granted {
605605
_delayedInitParameters = nil;
606606
}
607607

608-
+ (BOOL)getPrivacyConsent {
609-
return [OSPrivacyConsentController getPrivacyConsent];
610-
}
611-
612608
+ (void)downloadIOSParamsWithAppId:(NSString *)appId {
613609
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:@"Downloading iOS parameters for this application"];
614610
_didCallDownloadParameters = true;

0 commit comments

Comments
 (0)