@@ -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) {
@@ -383,8 +386,11 @@ - (NSString *)developmentPlatformName {
383386}
384387
385388- (void )setDevelopmentPlatformName : (NSString *)developmentPlatformName {
386- FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSDevelopmentPlatformNameKey,
387- developmentPlatformName);
389+ [self waitForContextInit: developmentPlatformName
390+ callback: ^{
391+ FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSDevelopmentPlatformNameKey,
392+ developmentPlatformName);
393+ }];
388394}
389395
390396- (NSString *)developmentPlatformVersion {
@@ -393,8 +399,11 @@ - (NSString *)developmentPlatformVersion {
393399}
394400
395401- (void )setDevelopmentPlatformVersion : (NSString *)developmentPlatformVersion {
396- FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSDevelopmentPlatformVersionKey,
397- developmentPlatformVersion);
402+ [self waitForContextInit: developmentPlatformVersion
403+ callback: ^{
404+ FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSDevelopmentPlatformVersionKey,
405+ developmentPlatformVersion);
406+ }];
398407}
399408
400409#pragma mark - API: Errors and Exceptions
@@ -445,4 +454,16 @@ - (void)rolloutsStateDidChange:(FIRRolloutsState *_Nonnull)rolloutsState {
445454 [_remoteConfigManager updateRolloutsStateWithRolloutsState: rolloutsState
446455 reportID: currentReportID];
447456}
457+
458+ #pragma mark - Private Helpsers
459+ - (void )waitForContextInit : (NSString *)contextLog callback : (void (^)(void ))callback {
460+ if (!_contextInitPromise) {
461+ FIRCLSErrorLog (@" Crashlytics method called before SDK was initialized: %@ " , contextLog);
462+ return ;
463+ }
464+ [_contextInitPromise then: ^id _Nullable (id _Nullable value) {
465+ callback ();
466+ return nil ;
467+ }];
468+ }
448469@end
0 commit comments