@@ -131,9 +131,11 @@ - (void)fetchConfigWithExpirationDuration:(NSTimeInterval)expirationDuration
131
131
FIRRemoteConfigHasDeviceContextChanged (_settings.deviceContext , _options.googleAppID );
132
132
133
133
__weak RCNConfigFetch *weakSelf = self;
134
- RCNConfigFetch *fetchWithExpirationSelf = weakSelf;
135
- dispatch_async (fetchWithExpirationSelf->_lockQueue , ^{
136
- RCNConfigFetch *strongSelf = fetchWithExpirationSelf;
134
+ dispatch_async (_lockQueue, ^{
135
+ RCNConfigFetch *strongSelf = weakSelf;
136
+ if (strongSelf == nil ) {
137
+ return ;
138
+ }
137
139
138
140
// Check whether we are outside of the minimum fetch interval.
139
141
if (![strongSelf->_settings hasMinimumFetchIntervalElapsed: expirationDuration] &&
@@ -216,15 +218,22 @@ - (void)refreshInstallationsTokenWithCompletionHandler:
216
218
NSLocalizedDescriptionKey : errorDescription
217
219
}]];
218
220
}
221
+
222
+ __weak RCNConfigFetch *weakSelf = self;
219
223
FIRInstallationsTokenHandler installationsTokenHandler = ^(
220
224
FIRInstallationsAuthTokenResult *tokenResult, NSError *error) {
225
+ RCNConfigFetch *strongSelf = weakSelf;
226
+ if (strongSelf == nil ) {
227
+ return ;
228
+ }
229
+
221
230
if (!tokenResult || !tokenResult.authToken || error) {
222
231
NSString *errorDescription =
223
232
[NSString stringWithFormat: @" Failed to get installations token. Error : %@ ." , error];
224
233
FIRLogError (kFIRLoggerRemoteConfig , @" I-RCN000073" , @" %@ " ,
225
234
[NSString stringWithFormat: @" %@ " , errorDescription]);
226
- self ->_settings .isFetchInProgress = NO ;
227
- return [self
235
+ strongSelf ->_settings .isFetchInProgress = NO ;
236
+ return [strongSelf
228
237
reportCompletionOnHandler: completionHandler
229
238
withStatus: FIRRemoteConfigFetchStatusFailure
230
239
withError: [NSError errorWithDomain: FIRRemoteConfigErrorDomain
@@ -235,14 +244,19 @@ - (void)refreshInstallationsTokenWithCompletionHandler:
235
244
}
236
245
237
246
// We have a valid token. Get the backing installationID.
238
- __weak RCNConfigFetch *weakSelf = self;
239
247
[installations installationIDWithCompletion: ^(NSString *_Nullable identifier,
240
248
NSError *_Nullable error) {
241
249
RCNConfigFetch *strongSelf = weakSelf;
250
+ if (strongSelf == nil ) {
251
+ return ;
252
+ }
242
253
243
254
// Dispatch to the RC serial queue to update settings on the queue.
244
255
dispatch_async (strongSelf->_lockQueue , ^{
245
256
RCNConfigFetch *strongSelfQueue = weakSelf;
257
+ if (strongSelfQueue == nil ) {
258
+ return ;
259
+ }
246
260
247
261
// Update config settings with the IID and token.
248
262
strongSelfQueue->_settings .configInstallationsToken = tokenResult.authToken ;
@@ -337,17 +351,17 @@ - (void)fetchWithUserProperties:(NSDictionary *)userProperties
337
351
@" config fetch completed. Error: %@ StatusCode: %ld " , (error ? error : @" nil" ),
338
352
(long )[((NSHTTPURLResponse *)response) statusCode ]);
339
353
340
- // The fetch has completed.
341
- self->_settings .isFetchInProgress = NO ;
342
-
343
354
RCNConfigFetch *fetcherCompletionSelf = weakSelf;
344
- if (! fetcherCompletionSelf) {
355
+ if (fetcherCompletionSelf == nil ) {
345
356
return ;
346
- };
357
+ }
358
+
359
+ // The fetch has completed.
360
+ fetcherCompletionSelf->_settings .isFetchInProgress = NO ;
347
361
348
362
dispatch_async (fetcherCompletionSelf->_lockQueue , ^{
349
363
RCNConfigFetch *strongSelf = weakSelf;
350
- if (! strongSelf) {
364
+ if (strongSelf == nil ) {
351
365
return ;
352
366
}
353
367
@@ -464,8 +478,8 @@ - (void)fetchWithUserProperties:(NSDictionary *)userProperties
464
478
// Add the fetched config to the database.
465
479
if (fetchedConfig) {
466
480
// Update config content to cache and DB.
467
- [self ->_content updateConfigContentWithResponse: fetchedConfig
468
- forNamespace: self ->_FIRNamespace];
481
+ [strongSelf ->_content updateConfigContentWithResponse: fetchedConfig
482
+ forNamespace: strongSelf ->_FIRNamespace];
469
483
// Update experiments.
470
484
[strongSelf->_experiment
471
485
updateExperimentsWithResponse: fetchedConfig[RCNFetchResponseKeyExperimentDescriptions]];
@@ -476,11 +490,12 @@ - (void)fetchWithUserProperties:(NSDictionary *)userProperties
476
490
477
491
// We had a successful fetch. Update the current eTag in settings if different.
478
492
NSString *latestETag = ((NSHTTPURLResponse *)response).allHeaderFields [kETagHeaderName ];
479
- if (!self->_settings .lastETag || !([self ->_settings.lastETag isEqualToString: latestETag])) {
480
- self->_settings .lastETag = latestETag;
493
+ if (!strongSelf->_settings .lastETag ||
494
+ !([strongSelf->_settings.lastETag isEqualToString: latestETag])) {
495
+ strongSelf->_settings .lastETag = latestETag;
481
496
}
482
497
483
- [self ->_settings updateMetadataWithFetchSuccessStatus: YES ];
498
+ [strongSelf ->_settings updateMetadataWithFetchSuccessStatus: YES ];
484
499
return [strongSelf reportCompletionOnHandler: completionHandler
485
500
withStatus: FIRRemoteConfigFetchStatusSuccess
486
501
withError: nil ];
0 commit comments