16
16
17
17
#import " FirebaseMessaging/Sources/Token/FIRMessagingTokenStore.h"
18
18
19
- #import < GoogleUtilities/GULSecureCoding.h>
20
19
#import " FirebaseMessaging/Sources/FIRMessagingConstants.h"
21
20
#import " FirebaseMessaging/Sources/FIRMessagingLogger.h"
22
21
#import " FirebaseMessaging/Sources/FIRMessagingUtilities.h"
@@ -88,18 +87,21 @@ + (nullable FIRMessagingTokenInfo *)tokenInfoFromKeychainItem:(NSData *)item {
88
87
// NOTE: Passing in nil to unarchiveObjectWithData will result in an iOS error logged
89
88
// in the console on iOS 10 and below. Avoid by checking item.data's existence.
90
89
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 ,
99
101
@" Unable to parse token info from Keychain item; item was in an "
100
- @" invalid format %@ " ,
101
- unarchiverError);
102
+ @" invalid format" );
102
103
tokenInfo = nil ;
104
+ } @finally {
103
105
}
104
106
}
105
107
return tokenInfo;
@@ -113,13 +115,13 @@ - (void)saveTokenInfo:(FIRMessagingTokenInfo *)tokenInfo
113
115
handler : (void (^)(NSError *))handler { // Keep the cachetime up-to-date.
114
116
tokenInfo.cacheTime = [NSDate date ];
115
117
// 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
123
125
NSString *account = FIRMessagingAppIdentifier ();
124
126
NSString *service = [[self class ] serviceKeyForAuthorizedEntity: tokenInfo.authorizedEntity
125
127
scope: tokenInfo.scope];
@@ -128,15 +130,14 @@ - (void)saveTokenInfo:(FIRMessagingTokenInfo *)tokenInfo
128
130
129
131
- (void )saveTokenInfoInCache : (FIRMessagingTokenInfo *)tokenInfo {
130
132
tokenInfo.cacheTime = [NSDate date ];
133
+ // TODO(chliangGoogle): Use the new API and secureCoding protocol.
131
134
// 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
140
141
NSString *account = FIRMessagingAppIdentifier ();
141
142
NSString *service = [[self class ] serviceKeyForAuthorizedEntity: tokenInfo.authorizedEntity
142
143
scope: tokenInfo.scope];
0 commit comments