Skip to content

Commit 68c6d9c

Browse files
authored
Migrate FCM codebase to new NSKeyedUnarchiver APIs. (#14457)
1 parent 2e1a8f7 commit 68c6d9c

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

FirebaseMessaging/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Unreleased
2+
- [fixed] Migrate FCM codebase to new NSKeyedUnarchiver APIs. (#14424).
3+
14
# 11.8.0
25
- [fixed] Don't cache FCM registration token operations. (#14352).
36

FirebaseMessaging/Sources/Token/FIRMessagingTokenInfo.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,13 @@ - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
176176
// users have upgraded to at least 10.19.0. Perhaps, after privacy manifests have been required
177177
// for awhile?
178178
@try {
179-
[NSKeyedUnarchiver setClass:[FIRMessagingAPNSInfo class]
180-
forClassName:@"FIRInstanceIDAPNSInfo"];
181-
#pragma clang diagnostic push
182-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
183-
rawAPNSInfo = [NSKeyedUnarchiver unarchiveObjectWithData:(NSData *)rawAPNSInfo];
179+
NSKeyedUnarchiver *unarchiver =
180+
[[NSKeyedUnarchiver alloc] initForReadingFromData:(NSData *)rawAPNSInfo error:nil];
181+
unarchiver.requiresSecureCoding = NO;
182+
[unarchiver setClass:[FIRMessagingAPNSInfo class] forClassName:@"FIRInstanceIDAPNSInfo"];
183+
rawAPNSInfo = [unarchiver decodeObjectForKey:NSKeyedArchiveRootObjectKey];
184+
[unarchiver finishDecoding];
184185
needsMigration = YES;
185-
#pragma clang diagnostic pop
186186
} @catch (NSException *exception) {
187187
FIRMessagingLoggerInfo(kFIRMessagingMessageCodeTokenInfoBadAPNSInfo,
188188
@"Could not parse raw APNS Info while parsing archived token info.");

FirebaseMessaging/Sources/Token/FIRMessagingTokenStore.m

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,14 @@ - (nullable FIRMessagingTokenInfo *)tokenInfoWithAuthorizedEntity:(NSString *)au
9999
+ (nullable FIRMessagingTokenInfo *)tokenInfoFromKeychainItem:(NSData *)item {
100100
// Check if it is saved as an archived FIRMessagingTokenInfo, otherwise return nil.
101101
FIRMessagingTokenInfo *tokenInfo = nil;
102-
// NOTE: Passing in nil to unarchiveObjectWithData will result in an iOS error logged
103-
// in the console on iOS 10 and below. Avoid by checking item.data's existence.
104102
if (item) {
105-
// TODO(chliangGoogle: Use the new API and secureCoding protocol.
106103
@try {
107-
#pragma clang diagnostic push
108-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
109-
[NSKeyedUnarchiver setClass:[FIRMessagingTokenInfo class]
110-
forClassName:@"FIRInstanceIDTokenInfo"];
111-
tokenInfo = [NSKeyedUnarchiver unarchiveObjectWithData:item];
112-
113-
#pragma clang diagnostic pop
114-
104+
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:item
105+
error:nil];
106+
unarchiver.requiresSecureCoding = NO;
107+
[unarchiver setClass:[FIRMessagingTokenInfo class] forClassName:@"FIRInstanceIDTokenInfo"];
108+
tokenInfo = [unarchiver decodeObjectForKey:NSKeyedArchiveRootObjectKey];
109+
[unarchiver finishDecoding];
115110
} @catch (NSException *exception) {
116111
FIRMessagingLoggerDebug(kFIRMessagingMessageCodeTokenStoreExceptionUnarchivingTokenInfo,
117112
@"Unable to parse token info from Keychain item; item was in an "

0 commit comments

Comments
 (0)