@@ -289,15 +289,21 @@ - (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+ return [FBLPromise resolvedWith: @YES ];
306+ }];
301307
302308#if CLS_METRICKIT_SUPPORTED
303309 if (@available (iOS 15 , *)) {
@@ -317,9 +323,12 @@ - (FBLPromise *)deleteUnsentReports {
317323 [self beginSettingsWithToken: dataCollectionToken];
318324
319325 // Wait for MetricKit data to be available, then continue to send reports and resolve promise.
320- promise = [[self waitForMetricKitData ]
326+ promise = [[reportProfilingPromise onQueue: _dispatchQueue
327+ then: ^id _Nullable (id _Nullable value) {
328+ return [self waitForMetricKitData ];
329+ }]
321330 onQueue: _dispatchQueue
322- then: ^id _Nullable (id _Nullable metricKitValue ) {
331+ then: ^id _Nullable (id _Nullable value ) {
323332 [self beginReportUploadsWithToken: dataCollectionToken blockingSend: launchFailure];
324333
325334 // If data collection is enabled, the SDK will not notify the user
@@ -335,29 +344,33 @@ - (FBLPromise *)deleteUnsentReports {
335344
336345 // Wait for an action to get sent, either from processReports: or automatic data collection,
337346 // and for MetricKit data to be available.
338- promise = [[FBLPromise all: @[ [ self waitForReportAction ], [ self waitForMetricKitData ] ]]
347+ promise = [[reportProfilingPromise
339348 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- }];
349+ then: ^id _Nullable (id _Nullable value) {
350+ return [FBLPromise all: @[ [self waitForReportAction ], [self waitForMetricKitData ] ]];
351+ }] onQueue: _dispatchQueue
352+ then: ^id _Nullable (NSArray *_Nullable wrappedActionAndData) {
353+ // Process the actions for the reports on disk.
354+ FIRCLSReportAction action =
355+ [[wrappedActionAndData firstObject ] reportActionValue ];
356+
357+ if (action == FIRCLSReportActionSend) {
358+ FIRCLSDebugLog (@" Sending unsent reports." );
359+ FIRCLSDataCollectionToken *dataCollectionToken =
360+ [FIRCLSDataCollectionToken validToken ];
361+
362+ [self beginSettingsWithToken: dataCollectionToken];
363+
364+ [self beginReportUploadsWithToken: dataCollectionToken blockingSend: NO ];
365+
366+ } else if (action == FIRCLSReportActionDelete) {
367+ FIRCLSDebugLog (@" Deleting unsent reports." );
368+ [self .existingReportManager deleteUnsentReports ];
369+ } else {
370+ FIRCLSErrorLog (@" Unknown report action: %d " , action);
371+ }
372+ return @(report != nil );
373+ }];
361374 }
362375
363376 if (report != nil ) {
@@ -412,24 +425,23 @@ - (void)beginReportUploadsWithToken:(FIRCLSDataCollectionToken *)token
412425 }
413426}
414427
415- - (BOOL )startCrashReporterWithProfilingReport : (FIRCLSInternalReport *)report {
428+ - (FBLPromise<NSNumber *> * )startCrashReporterWithProfilingReport : (FIRCLSInternalReport *)report {
416429 if (!report) {
417- return NO ;
418- }
419-
420- if (![self .contextManager setupContextWithReport: report
421- settings: self .settings
422- fileManager: _fileManager]) {
423- return NO ;
430+ return [FBLPromise resolvedWith: @NO ];
424431 }
425432
426- [self .notificationManager registerNotificationListener ];
433+ return [[self .contextManager setupContextWithReport: report
434+ settings: self .settings
435+ fileManager: _fileManager]
436+ then: ^id _Nullable (id _Nullable value) {
437+ [self .notificationManager registerNotificationListener ];
427438
428- [self .analyticsManager registerAnalyticsListener ];
439+ [self .analyticsManager registerAnalyticsListener ];
429440
430- [self crashReportingSetupCompleted ];
441+ [self crashReportingSetupCompleted ];
431442
432- return YES ;
443+ return [FBLPromise resolvedWith: @YES ];
444+ }];
433445}
434446
435447- (void )crashReportingSetupCompleted {
0 commit comments