Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ THE SOFTWARE.


@interface OSPrivacyConsentController : NSObject
+ (void)migrate;
+ (BOOL)requiresUserPrivacyConsent;
+ (void)consentGranted:(BOOL)granted;
+ (BOOL)getPrivacyConsent;
+ (BOOL)shouldLogMissingPrivacyConsentErrorWithMethodName:(NSString *)methodName;
+ (void)setRequiresPrivacyConsent:(BOOL)required;
@end
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ of this software and associated documentation files (the "Software"), to deal

@implementation OSPrivacyConsentController

+ (void)migrate {
[self migrateConsentGranted];
}

/// `GDPR_CONSENT_GRANTED` had previously been saved to the standard user defaults.
/// However, this value is also read from the NSE (for example, to send confirmed deliveries).
/// Migrate this value to the shared user defaults, if it exists.
+ (void)migrateConsentGranted {
long consentGrantedCacheFixVersion = 50210;
long sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_CORE defaultValue:0];

if (sdkVersion >= consentGrantedCacheFixVersion) {
return;
}

if ([OneSignalUserDefaults.initStandard keyExists:GDPR_CONSENT_GRANTED]) {
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"OSPrivacyConsentController migrating consent granted from version: %ld", sdkVersion]];
// The default value should never be used, however the getSavedBoolForKey method requires it
BOOL granted = [OneSignalUserDefaults.initStandard getSavedBoolForKey:GDPR_CONSENT_GRANTED defaultValue:false];
[OneSignalUserDefaults.initShared saveBoolForKey:GDPR_CONSENT_GRANTED withValue:granted];
}
}

+ (void)setRequiresPrivacyConsent:(BOOL)required {
OSRemoteParamController *remoteParamController = [OSRemoteParamController sharedController];

Expand All @@ -56,19 +79,13 @@ + (BOOL)requiresUserPrivacyConsent {
// if required and consent has not been previously granted, return false
BOOL requiresConsent = [[[NSBundle mainBundle] objectForInfoDictionaryKey:ONESIGNAL_REQUIRE_PRIVACY_CONSENT] boolValue] ?: false;
if (requiresConsent || shouldRequireUserConsent)
return ![OneSignalUserDefaults.initStandard getSavedBoolForKey:GDPR_CONSENT_GRANTED defaultValue:false];
return ![OneSignalUserDefaults.initShared getSavedBoolForKey:GDPR_CONSENT_GRANTED defaultValue:false];

return false;
}

+ (void)consentGranted:(BOOL)granted {
[OneSignalUserDefaults.initStandard saveBoolForKey:GDPR_CONSENT_GRANTED withValue:granted];
}

+ (BOOL)getPrivacyConsent {
// The default is the inverse of privacy consent required
BOOL defaultValue = ![OneSignalUserDefaults.initShared getSavedBoolForKey:OSUD_REQUIRES_USER_PRIVACY_CONSENT defaultValue:NO];
return [OneSignalUserDefaults.initStandard getSavedBoolForKey:GDPR_CONSENT_GRANTED defaultValue:defaultValue];
[OneSignalUserDefaults.initShared saveBoolForKey:GDPR_CONSENT_GRANTED withValue:granted];
}

+ (BOOL)shouldLogMissingPrivacyConsentErrorWithMethodName:(NSString *)methodName {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,15 @@
#define OSUD_CACHED_RECEIVED_IAM_IDS @"OSUD_CACHED_RECEIVED_IAM_IDS"
#define OSUD_CACHED_UNATTRIBUTED_UNIQUE_OUTCOME_EVENTS_SENT @"CACHED_UNATTRIBUTED_UNIQUE_OUTCOME_EVENTS_SENT" // * OSUD_CACHED_UNATTRIBUTED_UNIQUE_OUTCOME_EVENTS_SENT
#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

// Migration
#define OSUD_CACHED_SDK_VERSION @"OSUD_CACHED_SDK_VERSION"
/// Value used by all modules prior to 5.2.10
#define OSUD_LEGACY_CACHED_SDK_VERSION_FOR_MIGRATION @"OSUD_CACHED_SDK_VERSION"
/// Values added in 5.2.10 for each module to own its own migration
#define OSUD_CACHED_SDK_VERSION_FOR_CORE @"OSUD_CACHED_SDK_VERSION_FOR_CORE"
#define OSUD_CACHED_SDK_VERSION_FOR_OUTCOMES @"OSUD_CACHED_SDK_VERSION_FOR_OUTCOMES"
#define OSUD_CACHED_SDK_VERSION_FOR_IAM @"OSUD_CACHED_SDK_VERSION_FOR_IAM"

// Time Tracking
#define OSUD_APP_LAST_CLOSED_TIME @"GT_LAST_CLOSED_TIME" // * OSUD_APP_LAST_CLOSED_TIME
#define OSUD_UNSENT_ACTIVE_TIME @"GT_UNSENT_ACTIVE_TIME" // * OSUD_UNSENT_ACTIVE_TIME
Expand Down
1 change: 1 addition & 0 deletions iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
// TODO: Testing: Should this class be defined in this file?
@interface OneSignalCoreImpl : NSObject

+ (void)migrate;
+ (void)setSharedClient:(nonnull id<IOneSignalClient>)client;
+ (nonnull id<IOneSignalClient>)sharedClient;

Expand Down
29 changes: 29 additions & 0 deletions iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCore.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,35 @@

@implementation OneSignalCoreImpl

+ (void)migrate {
[self migrateCachedSdkVersion];
[OSPrivacyConsentController migrate];
[self saveCurrentSDKVersion];
}

/// Every module should be responsible for its own migration, as it is possible for one module
/// to finish migrating without another undergoing migration yet.
/// See https://github.com/OneSignal/OneSignal-iOS-SDK/pull/1541
+ (void)migrateCachedSdkVersion {
if (![OneSignalUserDefaults.initShared keyExists:OSUD_LEGACY_CACHED_SDK_VERSION_FOR_MIGRATION]) {
return;
}

// The default value should never be used, however the getSavedIntegerForKey method requires it
long sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey:OSUD_LEGACY_CACHED_SDK_VERSION_FOR_MIGRATION defaultValue:0];
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"OneSignalCoreImpl migrating cached SDK versions from version: %ld", sdkVersion]];

[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_CORE withValue:sdkVersion];
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_OUTCOMES withValue:sdkVersion];
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_IAM withValue:sdkVersion];
[OneSignalUserDefaults.initShared removeValueForKey:OSUD_LEGACY_CACHED_SDK_VERSION_FOR_MIGRATION];
}

+ (void)saveCurrentSDKVersion {
int currentVersion = [ONESIGNAL_VERSION intValue];
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_CORE withValue:currentVersion];
}

static id<IOneSignalClient> _sharedClient;
+ (id<IOneSignalClient>)sharedClient {
if (!_sharedClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ + (void)addActionButtonsToExtentionRequest:(UNNotificationRequest*)request
+ (void)onNotificationReceived:(NSString *)receivedNotificationId withBlockingTask:(dispatch_semaphore_t)semaphore {
if (receivedNotificationId && ![receivedNotificationId isEqualToString:@""]) {
// If update was made without app being initialized/launched before -> migrate
[OneSignalCoreImpl migrate];
[OSOutcomes migrate];
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"NSE request received, sessionManager: %@", [OSSessionManager sharedSessionManager]]];
// Save received notification id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ @implementation OSInAppMessageMigrationController
+(void)migrate {
[self migrateIAMRedisplayCache];
[self migrateToOSInAppMessageInternal];
[self saveCurrentSDKVersion];
}

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

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

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

@end
4 changes: 2 additions & 2 deletions iOS_SDK/OneSignalSDK/OneSignalOutcomes/OSOutcomes.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ + (void)migrate {
+ (void)migrateToVersion_02_14_00_AndGreater {
let influenceVersion = 21400;
let uniqueCacheOutcomeVersion = 21403;
long sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey:OSUD_CACHED_SDK_VERSION defaultValue:0];
long sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_OUTCOMES defaultValue:0];
if (sdkVersion < influenceVersion) {
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"Migrating OSIndirectNotification from version: %ld", sdkVersion]];

Expand All @@ -85,7 +85,7 @@ + (void)migrateToVersion_02_14_00_AndGreater {
}
+ (void)saveCurrentSDKVersion {
let currentVersion = [ONESIGNAL_VERSION intValue];
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION withValue:currentVersion];
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_OUTCOMES withValue:currentVersion];
}

#pragma mark Session namespace
Expand Down
39 changes: 2 additions & 37 deletions iOS_SDK/OneSignalSDK/Source/OSMigrationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,47 +40,12 @@ + (OSOutcomeEventsCache *)outcomeEventsCache;
@implementation OSMigrationController

- (void)migrate {
[self migrateToVersion_02_14_00_AndGreater];
[OneSignalCoreImpl migrate];
[OSOutcomes migrate];
let oneSignalInAppMessages = NSClassFromString(ONE_SIGNAL_IN_APP_MESSAGES_CLASS_NAME);
if (oneSignalInAppMessages != nil && [oneSignalInAppMessages respondsToSelector:@selector(migrate)]) {
[oneSignalInAppMessages performSelector:@selector(migrate)];
}
[self saveCurrentSDKVersion];
}

/**
* Support renaming of decodable classes for cached data
*/
- (void)migrateToVersion_02_14_00_AndGreater {
let influenceVersion = 21400;
let uniqueCacheOutcomeVersion = 21403;
long sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey:OSUD_CACHED_SDK_VERSION defaultValue:0];
if (sdkVersion < influenceVersion) {
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"Migrating OSIndirectNotification from version: %ld", sdkVersion]];

[NSKeyedUnarchiver setClass:[OSIndirectInfluence class] forClassName:@"OSIndirectNotification"];
NSArray<OSIndirectInfluence *> * indirectInfluenceData = [[OSInfluenceDataRepository sharedInfluenceDataRepository] lastNotificationsReceivedData];
if (indirectInfluenceData) {
[NSKeyedArchiver setClassName:@"OSIndirectInfluence" forClass:[OSIndirectInfluence class]];
[[OSInfluenceDataRepository sharedInfluenceDataRepository] saveNotifications:indirectInfluenceData];
}
}

if (sdkVersion < uniqueCacheOutcomeVersion) {
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"Migrating OSUniqueOutcomeNotification from version: %ld", sdkVersion]];

[NSKeyedUnarchiver setClass:[OSCachedUniqueOutcome class] forClassName:@"OSUniqueOutcomeNotification"];
NSArray<OSCachedUniqueOutcome *> * attributedCacheUniqueOutcomeEvents = [[OSOutcomeEventsCache sharedOutcomeEventsCache] getAttributedUniqueOutcomeEventSent];
if (attributedCacheUniqueOutcomeEvents) {
[NSKeyedArchiver setClassName:@"OSCachedUniqueOutcome" forClass:[OSCachedUniqueOutcome class]];
[[OSOutcomeEventsCache sharedOutcomeEventsCache] saveAttributedUniqueOutcomeEventNotificationIds:attributedCacheUniqueOutcomeEvents];
}
}
}

- (void)saveCurrentSDKVersion {
let currentVersion = [[OneSignal sdkVersionRaw] intValue];
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION withValue:currentVersion];
}

@end
4 changes: 0 additions & 4 deletions iOS_SDK/OneSignalSDK/Source/OneSignal.m
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,6 @@ + (void)setConsentGiven:(BOOL)granted {
_delayedInitParameters = nil;
}

+ (BOOL)getPrivacyConsent {
return [OSPrivacyConsentController getPrivacyConsent];
}

+ (void)downloadIOSParamsWithAppId:(NSString *)appId {
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:@"Downloading iOS parameters for this application"];
_didCallDownloadParameters = true;
Expand Down
Loading