@@ -197,58 +197,76 @@ - (void)fetchConfigWithExpirationDuration:(NSTimeInterval)expirationDuration
197
197
198
198
#pragma mark - Fetch helpers
199
199
200
- // / Refresh instance ID token before fetching config. Instance ID is an optional field in config
201
- // / request .
200
+ // / Refresh instance ID token before fetching config. Instance ID is now mandatory for fetch
201
+ // / requests to work.(b/14751422) .
202
202
- (void )refreshInstanceIDTokenAndFetchCheckInInfoWithCompletionHandler :
203
203
(FIRRemoteConfigFetchCompletion)completionHandler {
204
204
FIRInstanceID *instanceID = [FIRInstanceID instanceID ];
205
- // Only refresh instance ID when a valid sender ID is provided. If not, continue without
206
- // fetching instance ID. Instance ID is for data analytics purpose, which is only optional for
207
- // config fetching.
208
205
if (!_options.GCMSenderID ) {
209
- [self fetchCheckinInfoWithCompletionHandler: completionHandler];
210
- return ;
206
+ NSString *errorDescription = @" Failed to get GCMSenderID" ;
207
+ FIRLogError (kFIRLoggerRemoteConfig , @" I-RCN000074" , @" %@ " ,
208
+ [NSString stringWithFormat: @" %@ " , errorDescription]);
209
+ return [self
210
+ reportCompletionOnHandler: completionHandler
211
+ withStatus: FIRRemoteConfigFetchStatusFailure
212
+ withError: [NSError errorWithDomain: FIRRemoteConfigErrorDomain
213
+ code: FIRRemoteConfigErrorInternalError
214
+ userInfo: @{
215
+ NSLocalizedDescriptionKey : errorDescription
216
+ }]];
211
217
}
212
218
FIRInstanceIDTokenHandler instanceIDHandler = ^(NSString *token, NSError *error) {
213
- if (error) {
214
- FIRLogError (kFIRLoggerRemoteConfig , @" I-RCN000020" ,
215
- @" Failed to register InstanceID with error : %@ ." , error);
219
+ if (!token || error) {
220
+ NSString *errorDescription =
221
+ [NSString stringWithFormat: @" Failed to get InstanceID token. Error : %@ ." , error];
222
+ FIRLogError (kFIRLoggerRemoteConfig , @" I-RCN000073" , @" %@ " ,
223
+ [NSString stringWithFormat: @" %@ " , errorDescription]);
224
+ return [self
225
+ reportCompletionOnHandler: completionHandler
226
+ withStatus: FIRRemoteConfigFetchStatusFailure
227
+ withError: [NSError errorWithDomain: FIRRemoteConfigErrorDomain
228
+ code: FIRRemoteConfigErrorInternalError
229
+ userInfo: @{
230
+ NSLocalizedDescriptionKey : errorDescription
231
+ }]];
216
232
}
217
233
218
234
// If the token is available, try to get the instanceID.
219
235
__weak RCNConfigFetch *weakSelf = self;
220
- if (token) {
221
- [instanceID getIDWithHandler: ^(NSString *_Nullable identity, NSError *_Nullable error) {
222
- RCNConfigFetch *strongSelf = weakSelf;
223
-
224
- // Dispatch to the RC serial queue to update settings on the queue.
225
- dispatch_async (strongSelf->_lockQueue , ^{
226
- RCNConfigFetch *strongSelfQueue = weakSelf;
236
+ [instanceID getIDWithHandler: ^(NSString *_Nullable identity, NSError *_Nullable error) {
237
+ RCNConfigFetch *strongSelf = weakSelf;
227
238
228
- // Update config settings with the IID and token .
229
- strongSelfQueue-> _settings . configInstanceIDToken = [token copy ];
230
- strongSelfQueue-> _settings . configInstanceID = identity ;
239
+ // Dispatch to the RC serial queue to update settings on the queue .
240
+ dispatch_async (strongSelf-> _lockQueue , ^{
241
+ RCNConfigFetch * strongSelfQueue = weakSelf ;
231
242
232
- if (identity && !error) {
233
- FIRLogInfo (kFIRLoggerRemoteConfig , @" I-RCN000022" , @" Success to get iid : %@ ." ,
234
- strongSelfQueue->_settings .configInstanceID );
235
- } else {
236
- FIRLogWarning (kFIRLoggerRemoteConfig , @" I-RCN000055" , @" Error getting iid : %@ ." ,
237
- error);
238
- }
243
+ // Update config settings with the IID and token.
244
+ strongSelfQueue->_settings .configInstanceIDToken = [token copy ];
245
+ strongSelfQueue->_settings .configInstanceID = identity;
246
+
247
+ if (!identity || error) {
248
+ NSString *errorDescription =
249
+ [NSString stringWithFormat: @" Error getting iid : %@ ." , error];
250
+ FIRLogError (kFIRLoggerRemoteConfig , @" I-RCN000055" , @" %@ " ,
251
+ [NSString stringWithFormat: @" %@ " , errorDescription]);
252
+ return [self
253
+ reportCompletionOnHandler: completionHandler
254
+ withStatus: FIRRemoteConfigFetchStatusFailure
255
+ withError: [NSError
256
+ errorWithDomain: FIRRemoteConfigErrorDomain
257
+ code: FIRRemoteConfigErrorInternalError
258
+ userInfo: @{
259
+ NSLocalizedDescriptionKey : errorDescription
260
+ }]];
261
+ }
239
262
240
- // Continue the fetch regardless of whether fetch of instance ID succeeded.
241
- [strongSelfQueue fetchCheckinInfoWithCompletionHandler: completionHandler];
242
- });
243
- }];
263
+ FIRLogInfo (kFIRLoggerRemoteConfig , @" I-RCN000022" , @" Success to get iid : %@ ." ,
264
+ strongSelfQueue->_settings .configInstanceID );
244
265
245
- } else {
246
- dispatch_async (self->_lockQueue , ^{
247
- RCNConfigFetch *strongSelfQueue = weakSelf;
248
266
// Continue the fetch regardless of whether fetch of instance ID succeeded.
249
267
[strongSelfQueue fetchCheckinInfoWithCompletionHandler: completionHandler];
250
268
});
251
- }
269
+ }];
252
270
};
253
271
FIRLogDebug (kFIRLoggerRemoteConfig , @" I-RCN000039" , @" Starting requesting token." );
254
272
// Note: We expect the GCMSenderID to always be available by the time this request is made.
0 commit comments