Skip to content

Commit 1735b38

Browse files
committed
adding user setting APIs to context init chain
1 parent 03cffc3 commit 1735b38

File tree

1 file changed

+55
-16
lines changed

1 file changed

+55
-16
lines changed

Crashlytics/Crashlytics/FIRCrashlytics.m

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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,30 @@ - (void)deleteUnsentReports {
350360

351361
#pragma mark - API: setUserID
352362
- (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+
}];
354367
}
355368

356369
#pragma mark - API: setCustomValue
357370

358371
- (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+
}];
360380
}
361381

362382
- (void)setCustomKeysAndValues:(NSDictionary *)keysAndValues {
363-
FIRCLSUserLoggingRecordUserKeysAndValues(keysAndValues);
383+
[_contextInitPromise then:^id _Nullable(id _Nullable value) {
384+
FIRCLSUserLoggingRecordUserKeysAndValues(keysAndValues);
385+
return nil;
386+
}];
364387
}
365388

366389
#pragma mark - API: Development Platform
@@ -383,8 +406,16 @@ - (NSString *)developmentPlatformName {
383406
}
384407

385408
- (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+
}];
388419
}
389420

390421
- (NSString *)developmentPlatformVersion {
@@ -393,8 +424,16 @@ - (NSString *)developmentPlatformVersion {
393424
}
394425

395426
- (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+
}];
398437
}
399438

400439
#pragma mark - API: Errors and Exceptions

0 commit comments

Comments
 (0)