@@ -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,30 @@ - (void)deleteUnsentReports {
350
360
351
361
#pragma mark - API: setUserID
352
362
- (void )setUserID : (nullable NSString *)userID {
353
- FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSUserIdentifierKey, userID);
363
+ [_contextInitPromise then: ^id _Nullable (id _Nullable value) {
364
+ FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSUserIdentifierKey, userID);
365
+ return nil ;
366
+ }];
354
367
}
355
368
356
369
#pragma mark - API: setCustomValue
357
370
358
371
- (void )setCustomValue : (nullable id )value forKey : (NSString *)key {
359
- FIRCLSUserLoggingRecordUserKeyValue (key, value);
372
+ if (!_contextInitPromise) {
373
+ FIRCLSWarningLog (@" Context has not been inialized when set key: %@ , value: %@ " , key, value);
374
+ return ;
375
+ }
376
+ [_contextInitPromise then: ^id _Nullable (id _Nullable value) {
377
+ FIRCLSUserLoggingRecordUserKeyValue (key, value);
378
+ return nil ;
379
+ }];
360
380
}
361
381
362
382
- (void )setCustomKeysAndValues : (NSDictionary *)keysAndValues {
363
- FIRCLSUserLoggingRecordUserKeysAndValues (keysAndValues);
383
+ [_contextInitPromise then: ^id _Nullable (id _Nullable value) {
384
+ FIRCLSUserLoggingRecordUserKeysAndValues (keysAndValues);
385
+ return nil ;
386
+ }];
364
387
}
365
388
366
389
#pragma mark - API: Development Platform
@@ -383,8 +406,16 @@ - (NSString *)developmentPlatformName {
383
406
}
384
407
385
408
- (void )setDevelopmentPlatformName : (NSString *)developmentPlatformName {
386
- FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSDevelopmentPlatformNameKey,
387
- developmentPlatformName);
409
+ if (!_contextInitPromise) {
410
+ FIRCLSWarningLog (@" Context has not been inialized when set platform name: %@ " ,
411
+ developmentPlatformName);
412
+ return ;
413
+ }
414
+ [_contextInitPromise then: ^id _Nullable (id _Nullable value) {
415
+ FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSDevelopmentPlatformNameKey,
416
+ developmentPlatformName);
417
+ return nil ;
418
+ }];
388
419
}
389
420
390
421
- (NSString *)developmentPlatformVersion {
@@ -393,8 +424,16 @@ - (NSString *)developmentPlatformVersion {
393
424
}
394
425
395
426
- (void )setDevelopmentPlatformVersion : (NSString *)developmentPlatformVersion {
396
- FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSDevelopmentPlatformVersionKey,
397
- developmentPlatformVersion);
427
+ if (!_contextInitPromise) {
428
+ FIRCLSWarningLog (@" Context has not been inialized when set platform version: %@ " ,
429
+ developmentPlatformVersion);
430
+ return ;
431
+ }
432
+ [_contextInitPromise then: ^id _Nullable (id _Nullable value) {
433
+ FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSDevelopmentPlatformVersionKey,
434
+ developmentPlatformVersion);
435
+ return nil ;
436
+ }];
398
437
}
399
438
400
439
#pragma mark - API: Errors and Exceptions
0 commit comments