1616
1717#import " FirebaseMessaging/Sources/Token/FIRMessagingTokenStore.h"
1818
19- #import < GoogleUtilities/GULSecureCoding.h>
2019#import " FirebaseMessaging/Sources/FIRMessagingConstants.h"
2120#import " FirebaseMessaging/Sources/FIRMessagingLogger.h"
2221#import " FirebaseMessaging/Sources/FIRMessagingUtilities.h"
@@ -88,18 +87,21 @@ + (nullable FIRMessagingTokenInfo *)tokenInfoFromKeychainItem:(NSData *)item {
8887 // NOTE: Passing in nil to unarchiveObjectWithData will result in an iOS error logged
8988 // in the console on iOS 10 and below. Avoid by checking item.data's existence.
9089 if (item) {
91- NSError *unarchiverError;
92- tokenInfo = [GULSecureCoding
93- unarchivedObjectOfClasses: [NSSet
94- setWithObjects: FIRMessagingTokenInfo.class, NSDate .class, nil ]
95- fromData: item
96- error: &unarchiverError];
97- if (unarchiverError) {
98- FIRMessagingLoggerDebug (kFIRMessagingMessageCodeTokenStoreUnarchivingTokenInfo ,
90+ // TODO(chliangGoogle: Use the new API and secureCoding protocol.
91+ @try {
92+ #pragma clang diagnostic push
93+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
94+ [NSKeyedUnarchiver setClass: [FIRMessagingTokenInfo class ]
95+ forClassName: @" FIRInstanceIDTokenInfo" ];
96+ tokenInfo = [NSKeyedUnarchiver unarchiveObjectWithData: item];
97+ #pragma clang diagnostic pop
98+
99+ } @catch (NSException *exception) {
100+ FIRMessagingLoggerDebug (kFIRMessagingMessageCodeTokenStoreExceptionUnarchivingTokenInfo ,
99101 @" Unable to parse token info from Keychain item; item was in an "
100- @" invalid format %@ " ,
101- unarchiverError);
102+ @" invalid format" );
102103 tokenInfo = nil ;
104+ } @finally {
103105 }
104106 }
105107 return tokenInfo;
@@ -113,13 +115,13 @@ - (void)saveTokenInfo:(FIRMessagingTokenInfo *)tokenInfo
113115 handler : (void (^)(NSError *))handler { // Keep the cachetime up-to-date.
114116 tokenInfo.cacheTime = [NSDate date ];
115117 // Always write to the Keychain, so that the cacheTime is up-to-date.
116- NSError *archiverError ;
117- NSData *tokenInfoData = [GULSecureCoding archivedDataWithRootObject: tokenInfo
118- error: &archiverError ];
119- if (archiverError) {
120- FIRMessagingLoggerDebug ( kFIRMessagingMessageCodeTokenStoreArchiveError ,
121- @" Failed to archive token info: %@ " , archiverError) ;
122- }
118+ NSData *tokenInfoData ;
119+ // TODO(chliangGoogle: Use the new API and secureCoding protocol.
120+ [ NSKeyedArchiver setClassName: @" FIRInstanceIDTokenInfo " forClass: [FIRMessagingTokenInfo class ] ];
121+ # pragma clang diagnostic push
122+ # pragma clang diagnostic ignored "-Wdeprecated-declarations"
123+ tokenInfoData = [ NSKeyedArchiver archivedDataWithRootObject: tokenInfo] ;
124+ # pragma clang diagnostic pop
123125 NSString *account = FIRMessagingAppIdentifier ();
124126 NSString *service = [[self class ] serviceKeyForAuthorizedEntity: tokenInfo.authorizedEntity
125127 scope: tokenInfo.scope];
@@ -128,15 +130,14 @@ - (void)saveTokenInfo:(FIRMessagingTokenInfo *)tokenInfo
128130
129131- (void )saveTokenInfoInCache : (FIRMessagingTokenInfo *)tokenInfo {
130132 tokenInfo.cacheTime = [NSDate date ];
133+ // TODO(chliangGoogle): Use the new API and secureCoding protocol.
131134 // Always write to the Keychain, so that the cacheTime is up-to-date.
132- NSError *archiverError;
133- NSData *tokenInfoData = [GULSecureCoding archivedDataWithRootObject: tokenInfo
134- error: &archiverError];
135- if (archiverError) {
136- FIRMessagingLoggerDebug (kFIRMessagingMessageCodeTokenStoreArchiveError ,
137- @" Failed to archive token info: %@ " , archiverError);
138- }
139-
135+ NSData *tokenInfoData;
136+ [NSKeyedArchiver setClassName: @" FIRInstanceIDTokenInfo" forClass: [FIRMessagingTokenInfo class ]];
137+ #pragma clang diagnostic push
138+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
139+ tokenInfoData = [NSKeyedArchiver archivedDataWithRootObject: tokenInfo];
140+ #pragma clang diagnostic pop
140141 NSString *account = FIRMessagingAppIdentifier ();
141142 NSString *service = [[self class ] serviceKeyForAuthorizedEntity: tokenInfo.authorizedEntity
142143 scope: tokenInfo.scope];
0 commit comments