@@ -140,6 +140,7 @@ + (BOOL)supportsSecureCoding {
140
140
}
141
141
142
142
- (nullable instancetype )initWithCoder : (NSCoder *)aDecoder {
143
+ BOOL needsMigration = NO ;
143
144
// These value cannot be nil
144
145
145
146
id authorizedEntity = [aDecoder decodeObjectForKey: kFIRInstanceIDAuthorizedEntityKey ];
@@ -172,7 +173,25 @@ - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
172
173
FIRMessagingAPNSInfo *rawAPNSInfo = [aDecoder decodeObjectOfClasses: classes
173
174
forKey: kFIRInstanceIDAPNSInfoKey ];
174
175
if (rawAPNSInfo && ![rawAPNSInfo isKindOfClass: [FIRMessagingAPNSInfo class ]]) {
175
- return nil ;
176
+ // If the decoder fails to decode a FIRMessagingAPNSInfo, check if this was archived by a
177
+ // FirebaseMessaging 10.18.0 or earlier.
178
+ // TODO(#12246) This block may be replaced with `rawAPNSInfo = nil` once we're confident all
179
+ // users have upgraded to at least 10.19.0. Perhaps, after privacy manifests have been required
180
+ // for awhile?
181
+ @try {
182
+ [NSKeyedUnarchiver setClass: [FIRMessagingAPNSInfo class ]
183
+ forClassName: @" FIRInstanceIDAPNSInfo" ];
184
+ #pragma clang diagnostic push
185
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
186
+ rawAPNSInfo = [NSKeyedUnarchiver unarchiveObjectWithData: (NSData *)rawAPNSInfo];
187
+ needsMigration = YES ;
188
+ #pragma clang diagnostic pop
189
+ } @catch (NSException *exception) {
190
+ FIRMessagingLoggerInfo (kFIRMessagingMessageCodeTokenInfoBadAPNSInfo ,
191
+ @" Could not parse raw APNS Info while parsing archived token info." );
192
+ rawAPNSInfo = nil ;
193
+ } @finally {
194
+ }
176
195
}
177
196
178
197
id cacheTime = [aDecoder decodeObjectForKey: kFIRInstanceIDCacheTimeKey ];
@@ -189,6 +208,7 @@ - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
189
208
_firebaseAppID = [firebaseAppID copy ];
190
209
_APNSInfo = [rawAPNSInfo copy ];
191
210
_cacheTime = cacheTime;
211
+ _needsMigration = needsMigration;
192
212
}
193
213
return self;
194
214
}
0 commit comments