@@ -289,15 +289,21 @@ - (FBLPromise *)deleteUnsentReports {
289
289
290
290
BOOL launchFailure = [self .launchMarker checkForAndCreateLaunchMarker ];
291
291
292
- FIRCLSInternalReport *report = [self setupCurrentReport: executionIdentifier];
292
+ __block FIRCLSInternalReport *report = [self setupCurrentReport: executionIdentifier];
293
293
if (!report) {
294
294
FIRCLSErrorLog (@" Unable to setup a new report" );
295
295
}
296
296
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
+ }];
301
307
302
308
#if CLS_METRICKIT_SUPPORTED
303
309
if (@available (iOS 15 , *)) {
@@ -317,9 +323,12 @@ - (FBLPromise *)deleteUnsentReports {
317
323
[self beginSettingsWithToken: dataCollectionToken];
318
324
319
325
// 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
+ }]
321
330
onQueue: _dispatchQueue
322
- then: ^id _Nullable (id _Nullable metricKitValue ) {
331
+ then: ^id _Nullable (id _Nullable value ) {
323
332
[self beginReportUploadsWithToken: dataCollectionToken blockingSend: launchFailure];
324
333
325
334
// If data collection is enabled, the SDK will not notify the user
@@ -335,29 +344,33 @@ - (FBLPromise *)deleteUnsentReports {
335
344
336
345
// Wait for an action to get sent, either from processReports: or automatic data collection,
337
346
// and for MetricKit data to be available.
338
- promise = [[FBLPromise all: @[ [ self waitForReportAction ], [ self waitForMetricKitData ] ]]
347
+ promise = [[reportProfilingPromise
339
348
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
+ }];
361
374
}
362
375
363
376
if (report != nil ) {
@@ -412,24 +425,23 @@ - (void)beginReportUploadsWithToken:(FIRCLSDataCollectionToken *)token
412
425
}
413
426
}
414
427
415
- - (BOOL )startCrashReporterWithProfilingReport : (FIRCLSInternalReport *)report {
428
+ - (FBLPromise<NSNumber *> * )startCrashReporterWithProfilingReport : (FIRCLSInternalReport *)report {
416
429
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 ];
424
431
}
425
432
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 ];
427
438
428
- [self .analyticsManager registerAnalyticsListener ];
439
+ [self .analyticsManager registerAnalyticsListener ];
429
440
430
- [self crashReportingSetupCompleted ];
441
+ [self crashReportingSetupCompleted ];
431
442
432
- return YES ;
443
+ return [FBLPromise resolvedWith: @YES ];
444
+ }];
433
445
}
434
446
435
447
- (void )crashReportingSetupCompleted {
0 commit comments