Another interesting thing is that I try to test Apple's BGTask demo(https://developer.apple.com/documentation/backgroundtasks/refreshing_and_maintaining_your_app_using_background_tasks ) according to this Apple’s Document: https://developer.apple.com/documentation/backgroundtasks/starting_and_terminating_tasks_during_development, but every time I got a crash when try to trigger two or more BGTasks in a row, here is the steps I do the test:
Put a breakpoint one line after BGTaskScheduler’s submit method in didFinishLaunchingWithOptions.
Run my app on my device and put it into background, the code is blocked by the breakpoint.
Use _simulateLaunchForTaskWithIdentifier to trigger a BGAppRefreshTask
Resume the app, the desired task is called, also the BGTaskScheduler’s submit method is called from this task's launch handler, code is blocked again by the breakpoint I put in step 1.
Use _simulateLaunchForTaskWithIdentifier to trigger another BGTask, crash, the description is also *** Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'No launch handler registered for task with identifier {public}@'
This crash is almost certain to happen, is it a bug for using iOS's private API?