@@ -111,6 +111,8 @@ @interface FIRCrashlytics () <FIRLibrary,
111
111
// Dependencies common to each of the Controllers
112
112
@property (nonatomic , strong ) FIRCLSManagerData *managerData;
113
113
114
+ @property (nonatomic , nullable ) FBLPromise *contextInitPromise;
115
+
114
116
@end
115
117
116
118
@implementation FIRCrashlytics
@@ -197,14 +199,15 @@ - (instancetype)initWithApp:(FIRApp *)app
197
199
});
198
200
}
199
201
200
- [[[_reportManager startWithProfiling ] then: ^id _Nullable (NSNumber *_Nullable value) {
201
- if (![value boolValue ]) {
202
- FIRCLSErrorLog (@" Crash reporting could not be initialized" );
203
- }
204
- return value;
205
- }] catch: ^void (NSError *error) {
206
- FIRCLSErrorLog (@" Crash reporting failed to initialize with error: %@ " , error);
207
- }];
202
+ _contextInitPromise =
203
+ [[[_reportManager startWithProfiling ] then: ^id _Nullable (NSNumber *_Nullable value) {
204
+ if (![value boolValue ]) {
205
+ FIRCLSErrorLog (@" Crash reporting could not be initialized" );
206
+ }
207
+ return value;
208
+ }] catch: ^void (NSError *error) {
209
+ FIRCLSErrorLog (@" Crash reporting failed to initialize with error: %@ " , error);
210
+ }];
208
211
209
212
// RemoteConfig subscription should be made after session report directory created.
210
213
if (remoteConfig) {
@@ -307,7 +310,14 @@ - (void)processDidCrashDuringPreviousExecution {
307
310
308
311
#pragma mark - API: Logging
309
312
- (void )log : (NSString *)msg {
310
- FIRCLSLog (@" %@ " , msg);
313
+ if (!_contextInitPromise) {
314
+ FIRCLSErrorLog (@" Context has not been inialized when log message: %@ " , msg);
315
+ return ;
316
+ }
317
+ [_contextInitPromise then: ^id _Nullable (id _Nullable value) {
318
+ FIRCLSLog (@" %@ " , msg);
319
+ return nil ;
320
+ }];
311
321
}
312
322
313
323
- (void )logWithFormat : (NSString *)format , ... {
@@ -350,17 +360,41 @@ - (void)deleteUnsentReports {
350
360
351
361
#pragma mark - API: setUserID
352
362
- (void )setUserID : (nullable NSString *)userID {
353
- FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSUserIdentifierKey, userID);
363
+ if (!_contextInitPromise) {
364
+ FIRCLSWarningLog (@" FIRCLSContext has not been inialized when set user id: %@ " , userID);
365
+ return ;
366
+ }
367
+
368
+ [_contextInitPromise then: ^id _Nullable (id _Nullable value) {
369
+ FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSUserIdentifierKey, userID);
370
+ return nil ;
371
+ }];
354
372
}
355
373
356
374
#pragma mark - API: setCustomValue
357
375
358
376
- (void )setCustomValue : (nullable id )value forKey : (NSString *)key {
359
- FIRCLSUserLoggingRecordUserKeyValue (key, value);
377
+ if (!_contextInitPromise) {
378
+ FIRCLSWarningLog (@" FIRCLSContext has not been inialized when set key: %@ , value: %@ " , key,
379
+ value);
380
+ return ;
381
+ }
382
+ [_contextInitPromise then: ^id _Nullable (id _Nullable value) {
383
+ FIRCLSUserLoggingRecordUserKeyValue (key, value);
384
+ return nil ;
385
+ }];
360
386
}
361
387
362
388
- (void )setCustomKeysAndValues : (NSDictionary *)keysAndValues {
363
- FIRCLSUserLoggingRecordUserKeysAndValues (keysAndValues);
389
+ if (!_contextInitPromise) {
390
+ FIRCLSWarningLog (@" FIRCLSContext has not been inialized when set keys and values: %@ " ,
391
+ keysAndValues);
392
+ return ;
393
+ }
394
+ [_contextInitPromise then: ^id _Nullable (id _Nullable value) {
395
+ FIRCLSUserLoggingRecordUserKeysAndValues (keysAndValues);
396
+ return nil ;
397
+ }];
364
398
}
365
399
366
400
#pragma mark - API: Development Platform
@@ -383,8 +417,16 @@ - (NSString *)developmentPlatformName {
383
417
}
384
418
385
419
- (void )setDevelopmentPlatformName : (NSString *)developmentPlatformName {
386
- FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSDevelopmentPlatformNameKey,
387
- developmentPlatformName);
420
+ if (!_contextInitPromise) {
421
+ FIRCLSWarningLog (@" FIRCLSContext has not been inialized when set platform name: %@ " ,
422
+ developmentPlatformName);
423
+ return ;
424
+ }
425
+ [_contextInitPromise then: ^id _Nullable (id _Nullable value) {
426
+ FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSDevelopmentPlatformNameKey,
427
+ developmentPlatformName);
428
+ return nil ;
429
+ }];
388
430
}
389
431
390
432
- (NSString *)developmentPlatformVersion {
@@ -393,8 +435,16 @@ - (NSString *)developmentPlatformVersion {
393
435
}
394
436
395
437
- (void )setDevelopmentPlatformVersion : (NSString *)developmentPlatformVersion {
396
- FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSDevelopmentPlatformVersionKey,
397
- developmentPlatformVersion);
438
+ if (!_contextInitPromise) {
439
+ FIRCLSWarningLog (@" FIRCLSContext has not been inialized when set platform version: %@ " ,
440
+ developmentPlatformVersion);
441
+ return ;
442
+ }
443
+ [_contextInitPromise then: ^id _Nullable (id _Nullable value) {
444
+ FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSDevelopmentPlatformVersionKey,
445
+ developmentPlatformVersion);
446
+ return nil ;
447
+ }];
398
448
}
399
449
400
450
#pragma mark - API: Errors and Exceptions
@@ -403,20 +453,41 @@ - (void)recordError:(NSError *)error {
403
453
}
404
454
405
455
- (void )recordError : (NSError *)error userInfo : (NSDictionary <NSString *, id> *)userInfo {
406
- NSString *rolloutsInfoJSON = [_remoteConfigManager getRolloutAssignmentsEncodedJsonString ];
407
- FIRCLSUserLoggingRecordError (error, userInfo, rolloutsInfoJSON);
456
+ if (!_contextInitPromise) {
457
+ FIRCLSWarningLog (@" FIRCLSContext has not been inialized when record error" );
458
+ return ;
459
+ }
460
+ [_contextInitPromise then: ^id _Nullable (id _Nullable value) {
461
+ NSString *rolloutsInfoJSON = [_remoteConfigManager getRolloutAssignmentsEncodedJsonString ];
462
+ FIRCLSUserLoggingRecordError (error, userInfo, rolloutsInfoJSON);
463
+ return nil ;
464
+ }];
408
465
}
409
466
410
467
- (void )recordExceptionModel : (FIRExceptionModel *)exceptionModel {
411
- NSString *rolloutsInfoJSON = [_remoteConfigManager getRolloutAssignmentsEncodedJsonString ];
412
- FIRCLSExceptionRecordModel (exceptionModel, rolloutsInfoJSON);
468
+ if (!_contextInitPromise) {
469
+ FIRCLSWarningLog (@" FIRCLSContext has not been inialized when record exception model" );
470
+ return ;
471
+ }
472
+ [_contextInitPromise then: ^id _Nullable (id _Nullable value) {
473
+ NSString *rolloutsInfoJSON = [_remoteConfigManager getRolloutAssignmentsEncodedJsonString ];
474
+ FIRCLSExceptionRecordModel (exceptionModel, rolloutsInfoJSON);
475
+ return nil ;
476
+ }];
413
477
}
414
478
415
479
- (void )recordOnDemandExceptionModel : (FIRExceptionModel *)exceptionModel {
416
- [self .managerData.onDemandModel
417
- recordOnDemandExceptionIfQuota: exceptionModel
418
- withDataCollectionEnabled: [self .dataArbiter isCrashlyticsCollectionEnabled ]
419
- usingExistingReportManager: self .existingReportManager];
480
+ if (!_contextInitPromise) {
481
+ FIRCLSWarningLog (@" FIRCLSContext has not been inialized when record on demand exception" );
482
+ return ;
483
+ }
484
+ [_contextInitPromise then: ^id _Nullable (id _Nullable value) {
485
+ [self .managerData.onDemandModel
486
+ recordOnDemandExceptionIfQuota: exceptionModel
487
+ withDataCollectionEnabled: [self .dataArbiter isCrashlyticsCollectionEnabled ]
488
+ usingExistingReportManager: self .existingReportManager];
489
+ return nil ;
490
+ }];
420
491
}
421
492
422
493
#pragma mark - FIRSessionsSubscriber
0 commit comments