@@ -289,15 +289,26 @@ - (FBLPromise *)deleteUnsentReports {
289289
290290 BOOL launchFailure = [self .launchMarker checkForAndCreateLaunchMarker ];
291291
292- FIRCLSInternalReport *report = [self setupCurrentReport: executionIdentifier];
292+ __block FIRCLSInternalReport *report = [self setupCurrentReport: executionIdentifier];
293293 if (!report) {
294294 FIRCLSErrorLog (@" Unable to setup a new report" );
295295 }
296296
297- if (![self startCrashReporterWithProfilingReport: report]) {
298- FIRCLSErrorLog (@" Unable to start crash reporter" );
299- report = nil ;
300- }
297+ FBLPromise<NSNumber *> *reportProfilingPromise;
298+ reportProfilingPromise =
299+ [[self startCrashReporterWithProfilingReport: report] then: ^id _Nullable (id _Nullable value) {
300+ if ([value isEqual: @NO ]) {
301+ FIRCLSErrorLog (@" Unable to start crash reporter" );
302+ report = nil ;
303+ return [FBLPromise resolvedWith: @NO ];
304+ }
305+
306+ // empty for disabled start-up time
307+ dispatch_async (FIRCLSGetLoggingQueue (), ^{
308+ FIRCLSUserLoggingWriteInternalKeyValue (FIRCLSStartTimeKey, @" " );
309+ });
310+ return [FBLPromise resolvedWith: @YES ];
311+ }];
301312
302313#if CLS_METRICKIT_SUPPORTED
303314 if (@available (iOS 15 , *)) {
@@ -317,9 +328,12 @@ - (FBLPromise *)deleteUnsentReports {
317328 [self beginSettingsWithToken: dataCollectionToken];
318329
319330 // Wait for MetricKit data to be available, then continue to send reports and resolve promise.
320- promise = [[self waitForMetricKitData ]
331+ promise = [[reportProfilingPromise onQueue: _dispatchQueue
332+ then: ^id _Nullable (id _Nullable value) {
333+ return [self waitForMetricKitData ];
334+ }]
321335 onQueue: _dispatchQueue
322- then: ^id _Nullable (id _Nullable metricKitValue ) {
336+ then: ^id _Nullable (id _Nullable value ) {
323337 [self beginReportUploadsWithToken: dataCollectionToken blockingSend: launchFailure];
324338
325339 // If data collection is enabled, the SDK will not notify the user
@@ -335,36 +349,33 @@ - (FBLPromise *)deleteUnsentReports {
335349
336350 // Wait for an action to get sent, either from processReports: or automatic data collection,
337351 // and for MetricKit data to be available.
338- promise = [[FBLPromise all: @[ [ self waitForReportAction ], [ self waitForMetricKitData ] ]]
352+ promise = [[reportProfilingPromise
339353 onQueue: _dispatchQueue
340- then: ^id _Nullable (NSArray *_Nullable wrappedActionAndData) {
341- // Process the actions for the reports on disk.
342- FIRCLSReportAction action = [[wrappedActionAndData firstObject ] reportActionValue ];
343-
344- if (action == FIRCLSReportActionSend) {
345- FIRCLSDebugLog (@" Sending unsent reports." );
346- FIRCLSDataCollectionToken *dataCollectionToken =
347- [FIRCLSDataCollectionToken validToken ];
348-
349- [self beginSettingsWithToken: dataCollectionToken];
350-
351- [self beginReportUploadsWithToken: dataCollectionToken blockingSend: NO ];
352-
353- } else if (action == FIRCLSReportActionDelete) {
354- FIRCLSDebugLog (@" Deleting unsent reports." );
355- [self .existingReportManager deleteUnsentReports ];
356- } else {
357- FIRCLSErrorLog (@" Unknown report action: %d " , action);
358- }
359- return @(report != nil );
360- }];
361- }
362-
363- if (report != nil ) {
364- // empty for disabled start-up time
365- dispatch_async (FIRCLSGetLoggingQueue (), ^{
366- FIRCLSUserLoggingWriteInternalKeyValue (FIRCLSStartTimeKey, @" " );
367- });
354+ then: ^id _Nullable (id _Nullable value) {
355+ return [FBLPromise all: @[ [self waitForReportAction ], [self waitForMetricKitData ] ]];
356+ }] onQueue: _dispatchQueue
357+ then: ^id _Nullable (NSArray *_Nullable wrappedActionAndData) {
358+ // Process the actions for the reports on disk.
359+ FIRCLSReportAction action =
360+ [[wrappedActionAndData firstObject ] reportActionValue ];
361+
362+ if (action == FIRCLSReportActionSend) {
363+ FIRCLSDebugLog (@" Sending unsent reports." );
364+ FIRCLSDataCollectionToken *dataCollectionToken =
365+ [FIRCLSDataCollectionToken validToken ];
366+
367+ [self beginSettingsWithToken: dataCollectionToken];
368+
369+ [self beginReportUploadsWithToken: dataCollectionToken blockingSend: NO ];
370+
371+ } else if (action == FIRCLSReportActionDelete) {
372+ FIRCLSDebugLog (@" Deleting unsent reports." );
373+ [self .existingReportManager deleteUnsentReports ];
374+ } else {
375+ FIRCLSErrorLog (@" Unknown report action: %d " , action);
376+ }
377+ return @(report != nil );
378+ }];
368379 }
369380
370381 // To make the code more predictable and therefore testable, don't resolve the startup promise
@@ -412,24 +423,23 @@ - (void)beginReportUploadsWithToken:(FIRCLSDataCollectionToken *)token
412423 }
413424}
414425
415- - (BOOL )startCrashReporterWithProfilingReport : (FIRCLSInternalReport *)report {
426+ - (FBLPromise<NSNumber *> * )startCrashReporterWithProfilingReport : (FIRCLSInternalReport *)report {
416427 if (!report) {
417- return NO ;
418- }
419-
420- if (![self .contextManager setupContextWithReport: report
421- settings: self .settings
422- fileManager: _fileManager]) {
423- return NO ;
428+ return [FBLPromise resolvedWith: @NO ];
424429 }
425430
426- [self .notificationManager registerNotificationListener ];
431+ return [[self .contextManager setupContextWithReport: report
432+ settings: self .settings
433+ fileManager: _fileManager]
434+ then: ^id _Nullable (id _Nullable value) {
435+ [self .notificationManager registerNotificationListener ];
427436
428- [self .analyticsManager registerAnalyticsListener ];
437+ [self .analyticsManager registerAnalyticsListener ];
429438
430- [self crashReportingSetupCompleted ];
439+ [self crashReportingSetupCompleted ];
431440
432- return YES ;
441+ return [FBLPromise resolvedWith: @YES ];
442+ }];
433443}
434444
435445- (void )crashReportingSetupCompleted {
0 commit comments