@@ -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) {
@@ -383,8 +386,11 @@ - (NSString *)developmentPlatformName {
383
386
}
384
387
385
388
- (void )setDevelopmentPlatformName : (NSString *)developmentPlatformName {
386
- FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSDevelopmentPlatformNameKey,
387
- developmentPlatformName);
389
+ [self waitForContextInit: developmentPlatformName
390
+ callback: ^{
391
+ FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSDevelopmentPlatformNameKey,
392
+ developmentPlatformName);
393
+ }];
388
394
}
389
395
390
396
- (NSString *)developmentPlatformVersion {
@@ -393,8 +399,11 @@ - (NSString *)developmentPlatformVersion {
393
399
}
394
400
395
401
- (void )setDevelopmentPlatformVersion : (NSString *)developmentPlatformVersion {
396
- FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSDevelopmentPlatformVersionKey,
397
- developmentPlatformVersion);
402
+ [self waitForContextInit: developmentPlatformVersion
403
+ callback: ^{
404
+ FIRCLSUserLoggingRecordInternalKeyValue (FIRCLSDevelopmentPlatformVersionKey,
405
+ developmentPlatformVersion);
406
+ }];
398
407
}
399
408
400
409
#pragma mark - API: Errors and Exceptions
@@ -445,4 +454,16 @@ - (void)rolloutsStateDidChange:(FIRRolloutsState *_Nonnull)rolloutsState {
445
454
[_remoteConfigManager updateRolloutsStateWithRolloutsState: rolloutsState
446
455
reportID: currentReportID];
447
456
}
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
+ }
448
469
@end
0 commit comments