Skip to content
Open
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
15 changes: 11 additions & 4 deletions iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalUserDefaults.m
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,22 @@
[self.userDefaults synchronize];
}

- (id _Nullable)getSavedCodeableDataForKey:(NSString * _Nonnull)key defaultValue:(id _Nullable)value {
if ([self keyExists:key])
return [NSKeyedUnarchiver unarchiveObjectWithData:[self.userDefaults objectForKey:key]];

if ([self keyExists:key]) {
NSData *data = [self.userDefaults objectForKey:key];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:data error:nil];
unarchiver.requiresSecureCoding = NO;
id result = [unarchiver decodeTopLevelObjectAndReturnError:nil];
[unarchiver finishDecoding];
return result;
}

Check warning on line 163 in iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalUserDefaults.m

View check run for this annotation

Claude / Claude Code Review

Migration @catch no longer triggers on corrupt archives

Minor behavior change to flag: the old `+[NSKeyedUnarchiver unarchiveObjectWithData:]` threw `NSException` on decode failures, which `migrateIAMRedisplayCache` in `OSInAppMessageMigrationController.m:50-68` catches to trigger corrupt-cache recovery. The new `initForReadingFromData:error:` + `decodeTopLevelObjectAndReturnError:` pair is documented to convert exceptions to `NSError` and return nil for some failure modes, so the recovery `@catch` may no longer fire for genuinely-corrupt archive byt
return value;
}

- (void)saveCodeableDataForKey:(NSString * _Nonnull)key withValue:(id _Nullable)value {
[self.userDefaults setObject:[NSKeyedArchiver archivedDataWithRootObject:value] forKey:key];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:value requiringSecureCoding:NO error:nil];
[self.userDefaults setObject:data forKey:key];
[self.userDefaults synchronize];
}

Expand Down
Loading