Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Crashlytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
- [fixed] Make set development platform APIs to chain on Crashlytics context init promise.

# 12.3.0
- [fixed] Add missing nanopb dependency to fix SwiftPM builds when building
dynamically linked libraries. (#15276)
Expand Down
45 changes: 33 additions & 12 deletions Crashlytics/Crashlytics/FIRCrashlytics.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ @interface FIRCrashlytics () <FIRLibrary,
// Dependencies common to each of the Controllers
@property(nonatomic, strong) FIRCLSManagerData *managerData;

@property(nonatomic, nullable) FBLPromise *contextInitPromise;

@end

@implementation FIRCrashlytics
Expand Down Expand Up @@ -197,14 +199,15 @@ - (instancetype)initWithApp:(FIRApp *)app
});
}

[[[_reportManager startWithProfiling] then:^id _Nullable(NSNumber *_Nullable value) {
if (![value boolValue]) {
FIRCLSErrorLog(@"Crash reporting could not be initialized");
}
return value;
}] catch:^void(NSError *error) {
FIRCLSErrorLog(@"Crash reporting failed to initialize with error: %@", error);
}];
_contextInitPromise =
[[[_reportManager startWithProfiling] then:^id _Nullable(NSNumber *_Nullable value) {
if (![value boolValue]) {
FIRCLSErrorLog(@"Crash reporting could not be initialized");
}
return value;
}] catch:^void(NSError *error) {
FIRCLSErrorLog(@"Crash reporting failed to initialize with error: %@", error);
}];

// RemoteConfig subscription should be made after session report directory created.
if (remoteConfig) {
Expand Down Expand Up @@ -383,8 +386,11 @@ - (NSString *)developmentPlatformName {
}

- (void)setDevelopmentPlatformName:(NSString *)developmentPlatformName {
FIRCLSUserLoggingRecordInternalKeyValue(FIRCLSDevelopmentPlatformNameKey,
developmentPlatformName);
[self waitForContextInit:developmentPlatformName
callback:^{
FIRCLSUserLoggingRecordInternalKeyValue(FIRCLSDevelopmentPlatformNameKey,
developmentPlatformName);
}];
}

- (NSString *)developmentPlatformVersion {
Expand All @@ -393,8 +399,11 @@ - (NSString *)developmentPlatformVersion {
}

- (void)setDevelopmentPlatformVersion:(NSString *)developmentPlatformVersion {
FIRCLSUserLoggingRecordInternalKeyValue(FIRCLSDevelopmentPlatformVersionKey,
developmentPlatformVersion);
[self waitForContextInit:developmentPlatformVersion
callback:^{
FIRCLSUserLoggingRecordInternalKeyValue(FIRCLSDevelopmentPlatformVersionKey,
developmentPlatformVersion);
}];
}

#pragma mark - API: Errors and Exceptions
Expand Down Expand Up @@ -445,4 +454,16 @@ - (void)rolloutsStateDidChange:(FIRRolloutsState *_Nonnull)rolloutsState {
[_remoteConfigManager updateRolloutsStateWithRolloutsState:rolloutsState
reportID:currentReportID];
}

#pragma mark - Private Helpsers
- (void)waitForContextInit:(NSString *)contextLog callback:(void (^)(void))callback {
if (!_contextInitPromise) {
FIRCLSErrorLog(@"Crashlytics method called before SDK was initialized: %@", contextLog);
return;
}
[_contextInitPromise then:^id _Nullable(id _Nullable value) {
callback();
return nil;
}];
}
@end
23 changes: 23 additions & 0 deletions Crashlytics/UnitTests/FIRCLSContextManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,27 @@ - (void)test_settingSessionIDOutOfOrder_protoHasLastSessionID {
XCTAssertEqualObjects(adapter.identity.app_quality_session_id, TestContextSessionID2);
}

// This test is for chain on init promise for development platform related setters
- (void)test_promisesChainOnInitPromiseInOrder {
NSMutableArray<NSString *> *result = @[].mutableCopy;
NSMutableArray<NSString *> *expectation = @[].mutableCopy;

for (int j = 0; j < 100; j++) {
[expectation addObject:[NSString stringWithFormat:@"%d", j]];
}

FBLPromise *promise = [self.contextManager setupContextWithReport:self.report
settings:self.mockSettings
fileManager:self.fileManager];

for (int i = 0; i < 100; i++) {
[promise then:^id _Nullable(id _Nullable value) {
[result addObject:[NSString stringWithFormat:@"%d", i]];
if (i == 99) {
XCTAssertTrue([result isEqualToArray:expectation]);
}
return nil;
}];
}
}
@end
Loading