Skip to content

Commit bd29ed4

Browse files
committed
Adding migrate to load
Previously migrate was only in init. This will still allow crashes due to not migrating if customers call other public methods prior to calling OneSignal initWithLaunchOptions. We should avoid this as best as possible by migrating immediately. This implementation can be changed later to queue all methods until after init has been called so that we don't unnecessarily migrate.
1 parent ac6e382 commit bd29ed4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

iOS_SDK/OneSignalSDK/Source/OSMigrationController.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ @implementation OSMigrationController
4848
- (void)migrate {
4949
[self migrateToVersion_02_14_00_AndGreater];
5050
[self migrateIAMRedisplayCache];
51+
[self migrateToOSInAppMessageInternal];
5152
[self saveCurrentSDKVersion];
5253
}
5354

@@ -124,15 +125,19 @@ - (void)migrateToOSInAppMessageInternal {
124125
// Messages Array
125126
NSArray<OSInAppMessageInternal *> *messages = [OneSignalUserDefaults.initStandard getSavedCodeableDataForKey:OS_IAM_MESSAGES_ARRAY
126127
defaultValue:[NSArray<OSInAppMessageInternal *> new]];
127-
if (messages) {
128+
if (messages && messages.count) {
128129
[NSKeyedArchiver setClassName:@"OSInAppMessageInternal" forClass:[OSInAppMessageInternal class]];
129130
[OneSignalUserDefaults.initStandard saveCodeableDataForKey:OS_IAM_MESSAGES_ARRAY withValue:messages];
131+
} else {
132+
[OneSignalUserDefaults.initStandard saveCodeableDataForKey:OS_IAM_MESSAGES_ARRAY withValue:nil];
130133
}
131134

132135
// Redisplay Messages Dict
133136
NSMutableDictionary <NSString *, OSInAppMessageInternal *> *redisplayedInAppMessages = [[NSMutableDictionary alloc] initWithDictionary:[OneSignalUserDefaults.initStandard getSavedCodeableDataForKey:OS_IAM_REDISPLAY_DICTIONARY defaultValue:[NSMutableDictionary new]]];
134-
if (redisplayedInAppMessages) {
137+
if (redisplayedInAppMessages && redisplayedInAppMessages.count) {
135138
[OneSignalUserDefaults.initStandard saveCodeableDataForKey:OS_IAM_REDISPLAY_DICTIONARY withValue:redisplayedInAppMessages];
139+
} else {
140+
[OneSignalUserDefaults.initStandard saveCodeableDataForKey:OS_IAM_REDISPLAY_DICTIONARY withValue:nil];
136141
}
137142
}
138143
}

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,6 +3019,7 @@ + (void)load {
30193019
injectToProperClass(@selector(onesignalSetApplicationIconBadgeNumber:), @selector(setApplicationIconBadgeNumber:), @[], [OneSignalAppDelegate class], [UIApplication class]);
30203020

30213021
[self setupUNUserNotificationCenterDelegate];
3022+
[[OSMigrationController new] migrate];
30223023
sessionLaunchTime = [NSDate date];
30233024
}
30243025

0 commit comments

Comments
 (0)