Skip to content

Commit ba8674d

Browse files
authored
Adding development platform setter APIs to context init promise chain (#15356)
1 parent 61ca043 commit ba8674d

File tree

3 files changed

+59
-12
lines changed

3 files changed

+59
-12
lines changed

Crashlytics/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Unreleased
2+
- [fixed] Make set development platform APIs to chain on Crashlytics context init promise.
3+
14
# 12.3.0
25
- [fixed] Add missing nanopb dependency to fix SwiftPM builds when building
36
dynamically linked libraries. (#15276)

Crashlytics/Crashlytics/FIRCrashlytics.m

Lines changed: 33 additions & 12 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) {
@@ -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

Crashlytics/UnitTests/FIRCLSContextManagerTests.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,27 @@ - (void)test_settingSessionIDOutOfOrder_protoHasLastSessionID {
122122
XCTAssertEqualObjects(adapter.identity.app_quality_session_id, TestContextSessionID2);
123123
}
124124

125+
// This test is for chain on init promise for development platform related setters
126+
- (void)test_promisesChainOnInitPromiseInOrder {
127+
NSMutableArray<NSString *> *result = @[].mutableCopy;
128+
NSMutableArray<NSString *> *expectation = @[].mutableCopy;
129+
130+
for (int j = 0; j < 100; j++) {
131+
[expectation addObject:[NSString stringWithFormat:@"%d", j]];
132+
}
133+
134+
FBLPromise *promise = [self.contextManager setupContextWithReport:self.report
135+
settings:self.mockSettings
136+
fileManager:self.fileManager];
137+
138+
for (int i = 0; i < 100; i++) {
139+
[promise then:^id _Nullable(id _Nullable value) {
140+
[result addObject:[NSString stringWithFormat:@"%d", i]];
141+
if (i == 99) {
142+
XCTAssertTrue([result isEqualToArray:expectation]);
143+
}
144+
return nil;
145+
}];
146+
}
147+
}
125148
@end

0 commit comments

Comments
 (0)