@@ -111,6 +111,8 @@ @interface FIRCrashlytics () <FIRLibrary,
111111// Dependencies common to each of the Controllers
112112@property (nonatomic , strong ) FIRCLSManagerData *managerData;
113113
114+ @property (nonatomic , nullable ) FBLPromise *contextInitPromise;
115+
114116@end
115117
116118@implementation FIRCrashlytics
@@ -197,14 +199,15 @@ - (instancetype)initWithApp:(FIRApp *)app
197199 });
198200 }
199201
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+ }];
208211
209212 // RemoteConfig subscription should be made after session report directory created.
210213 if (remoteConfig) {
@@ -307,7 +310,14 @@ - (void)processDidCrashDuringPreviousExecution {
307310
308311#pragma mark - API: Logging
309312- (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+ }];
311321}
312322
313323- (void )logWithFormat : (NSString *)format , ... {
@@ -350,17 +360,41 @@ - (void)deleteUnsentReports {
350360
351361#pragma mark - API: setUserID
352362- (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+ }];
354372}
355373
356374#pragma mark - API: setCustomValue
357375
358376- (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+ }];
360386}
361387
362388- (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+ }];
364398}
365399
366400#pragma mark - API: Development Platform
@@ -383,8 +417,16 @@ - (NSString *)developmentPlatformName {
383417}
384418
385419- (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+ }];
388430}
389431
390432- (NSString *)developmentPlatformVersion {
@@ -393,8 +435,16 @@ - (NSString *)developmentPlatformVersion {
393435}
394436
395437- (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+ }];
398448}
399449
400450#pragma mark - API: Errors and Exceptions
@@ -403,20 +453,41 @@ - (void)recordError:(NSError *)error {
403453}
404454
405455- (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+ }];
408465}
409466
410467- (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+ }];
413477}
414478
415479- (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+ }];
420491}
421492
422493#pragma mark - FIRSessionsSubscriber
0 commit comments