I have a problem when my application goes into the background. I need to send the images for processing to the intelligence to wait for the intelligence to process and save them with me. However, the problem is when I start sending and pressing the home button and when my application goes into the background. How can I do this to end the process , whether or not the application goes into the background.
I added this before my function start send image.
DispatchQueue.global().async {
// Request the task assertion and save the ID.
self.backgroundTaskID = UIApplication.shared.
beginBackgroundTask (withName: "Finish Network Tasks") {
// End the task if time expires.
UIApplication.shared.endBackgroundTask(self.backgroundTaskID!)
self.backgroundTaskID = UIBackgroundTaskInvalid
}
and added this when all image is procesed
UIApplication.shared.endBackgroundTask(self.backgroundTaskID!)
self.backgroundTaskID = UIBackgroundTaskIdentifier.invalid
and i tested it work