Skip to content

Commit b9ddda6

Browse files
committed
Split up cached SDK versions for migration purposes
* Each module will own its migration and a separate cached SDK version to determine if it should do a migration. * This change is made because it is possible for one module to migrate while another has not yet, and caching the same SDK version will affect the second module's future migration when it reads the version from cache. * For example, this is currently a bug as of 5.2.9: - The extension can receive a notification during the time an app is updated without the app being initialized/launched before. This path calls a migration in the outcomes module. When the outcomes module is done migrating, it caches the new SDK version, overriding the previous cached version. - The next time the app starts up, in app messages may need to migrate but it is using the new SDK version that is cached by outcomes above, and skip a necessary migration.
1 parent 9a1ec13 commit b9ddda6

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

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/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

0 commit comments

Comments
 (0)