BGProcessingTaskRequest and URLSession

We use BGProcessingTaskRequest to perform tasks in the background in our app. We use URLSession.shared to make a http request to the server and retrieve data, then stored data in Core Data.

To force the execution of a background task, we use [[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"TASK_IDENTIFIER"]. After triggering the background task, we press the home button to put the app in the background. However, we noticed that URLSession.shared dataTask did not receive a response when the data with large size, and the background task stopped. If the app back to the foreground the request work again.

We would like to know how to properly use BGProcessingTaskRequest with URLSession and Core Data.

We referred to the following article for guidance: https://developer.apple.com/documentation/backgroundtasks/refreshing_and_maintaining_your_app_using_background_tasks

BGProcessingTaskRequest and URLSession
 
 
Q