Skip to content

Commit ac6e382

Browse files
committed
migration for OSInAppMessage -> OSInAppMessageInternal
1 parent d9c8036 commit ac6e382

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

iOS_SDK/OneSignalSDK/Source/OSMigrationController.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ of this software and associated documentation files (the "Software"), to deal
3636
#import "OneSignalCommonDefines.h"
3737
#import "OSInAppMessagingDefines.h"
3838
#import "OneSignalHelper.h"
39+
#import "OSInAppMessageInternal.h"
3940

4041
@interface OneSignal ()
4142
+ (OSInfluenceDataRepository *)influenceDataRepository;
@@ -110,6 +111,32 @@ - (void)migrateIAMRedisplayCache {
110111
}
111112
}
112113

114+
// OSInAppMessage has been made public
115+
// The old class has been renamed to OSInAppMessageInternal
116+
// We must set the new class name to the unarchiver to avoid crashing
117+
- (void)migrateToOSInAppMessageInternal {
118+
let nameChangeVersion = 30700;
119+
long sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey:OSUD_CACHED_SDK_VERSION defaultValue:0];
120+
if (sdkVersion < nameChangeVersion) {
121+
[OneSignal onesignal_Log:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"Migrating OSInAppMessage from version: %ld", sdkVersion]];
122+
123+
[NSKeyedUnarchiver setClass:[OSInAppMessageInternal class] forClassName:@"OSInAppMessage"];
124+
// Messages Array
125+
NSArray<OSInAppMessageInternal *> *messages = [OneSignalUserDefaults.initStandard getSavedCodeableDataForKey:OS_IAM_MESSAGES_ARRAY
126+
defaultValue:[NSArray<OSInAppMessageInternal *> new]];
127+
if (messages) {
128+
[NSKeyedArchiver setClassName:@"OSInAppMessageInternal" forClass:[OSInAppMessageInternal class]];
129+
[OneSignalUserDefaults.initStandard saveCodeableDataForKey:OS_IAM_MESSAGES_ARRAY withValue:messages];
130+
}
131+
132+
// Redisplay Messages Dict
133+
NSMutableDictionary <NSString *, OSInAppMessageInternal *> *redisplayedInAppMessages = [[NSMutableDictionary alloc] initWithDictionary:[OneSignalUserDefaults.initStandard getSavedCodeableDataForKey:OS_IAM_REDISPLAY_DICTIONARY defaultValue:[NSMutableDictionary new]]];
134+
if (redisplayedInAppMessages) {
135+
[OneSignalUserDefaults.initStandard saveCodeableDataForKey:OS_IAM_REDISPLAY_DICTIONARY withValue:redisplayedInAppMessages];
136+
}
137+
}
138+
}
139+
113140
- (void)saveCurrentSDKVersion {
114141
let currentVersion = [[OneSignal sdkVersionRaw] intValue];
115142
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION withValue:currentVersion];

0 commit comments

Comments
 (0)