Skip to content

Commit 2fc4120

Browse files
committed
Creating migration for Dictionary -> CodeableData for the redisplay dict
If the OS_IAM_REDISPLAY_CACHE is successfully read as Codeable data we don't need to migrate. If that fails try to read it as a dictionary and then save it as Codeable data. If that also fails then clear the cache because we cannot determine what data type was stored for the key.
1 parent 285115f commit 2fc4120

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

iOS_SDK/OneSignalSDK/Source/OSMigrationController.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ of this software and associated documentation files (the "Software"), to deal
3434
#import "OneSignal.h"
3535
#import "OneSignalUserDefaults.h"
3636
#import "OneSignalCommonDefines.h"
37+
#import "OSInAppMessagingDefines.h"
3738
#import "OneSignalHelper.h"
3839

3940
@interface OneSignal ()
@@ -45,6 +46,7 @@ @implementation OSMigrationController
4546

4647
- (void)migrate {
4748
[self migrateToVersion_02_14_00_AndGreater];
49+
[self migrateIAMRedisplayCache];
4850
[self saveCurrentSDKVersion];
4951
}
5052

@@ -78,6 +80,36 @@ - (void)migrateToVersion_02_14_00_AndGreater {
7880
}
7981
}
8082

83+
// Devices could potentially have bad data in the OS_IAM_REDISPLAY_DICTIONARY
84+
// that was saved as a dictionary and not CodeableData. Try to detect if that is the case
85+
// and save it is as CodeableData instead.
86+
- (void)migrateIAMRedisplayCache {
87+
let iamRedisplayCacheFixVersion = 30203;
88+
long sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey:OSUD_CACHED_SDK_VERSION defaultValue:0];
89+
if (sdkVersion >= iamRedisplayCacheFixVersion)
90+
return;
91+
92+
@try {
93+
__unused NSMutableDictionary *redisplayDict =[[NSMutableDictionary alloc] initWithDictionary:[OneSignalUserDefaults.initStandard
94+
getSavedCodeableDataForKey:OS_IAM_REDISPLAY_DICTIONARY
95+
defaultValue:[NSMutableDictionary new]]];
96+
} @catch (NSException *exception) {
97+
@try {
98+
// The redisplay IAMs might have been saved as a dictionary.
99+
// Try to read them as a dictionary and then save them as a codeable.
100+
NSMutableDictionary *redisplayDict = [[NSMutableDictionary alloc] initWithDictionary:[OneSignalUserDefaults.initStandard
101+
getSavedDictionaryForKey:OS_IAM_REDISPLAY_DICTIONARY
102+
defaultValue:[NSMutableDictionary new]]];
103+
[OneSignalUserDefaults.initStandard saveCodeableDataForKey:OS_IAM_REDISPLAY_DICTIONARY
104+
withValue:redisplayDict];
105+
} @catch (NSException *exception) {
106+
//Clear the cached redisplay dictionary of bad data
107+
[OneSignalUserDefaults.initStandard saveCodeableDataForKey:OS_IAM_REDISPLAY_DICTIONARY
108+
withValue:nil];
109+
}
110+
}
111+
}
112+
81113
- (void)saveCurrentSDKVersion {
82114
let currentVersion = [[OneSignal sdkVersionRaw] intValue];
83115
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION withValue:currentVersion];

0 commit comments

Comments
 (0)