What happens after BGContinuedProcessingTask "expires"?

If I create a BGContinuedProcessingTaskRequest, register it, and then "do work" within it appropriately reporting progress, and before my task has finished doing all the work it had to do, its expirationHandler triggers...

does the task later try again?

Or does it lose the execution opportunity until the app is next re-launched to the foreground?

In my testing, I never saw my task execute again once expired (which suggests the latter?).

I was able to easily force this expiry by starting my task, backgrounding my app, then launching the iOS Camera App. My example is just using test code inspired from https://developer.apple.com/documentation/backgroundtasks/performing-long-running-tasks-on-ios-and-ipados

                let request = BGContinuedProcessingTaskRequest(identifier: taskIdentifier, title: "Video Upload", subtitle: "Starting Upload")
                request.strategy = .queue
                
                BGTaskScheduler.shared.register(forTaskWithIdentifier: taskIdentifier, using: nil) { task in
                    guard let task = task as? BGContinuedProcessingTask else { return }
                    print("i am a good task")
                    var wasExpired = false
                    
                    task.expirationHandler = {
                        wasExpired = true
                    }

                    let progress = task.progress
                    progress.totalUnitCount = 100
                    while !progress.isFinished && !wasExpired {
                        progress.completedUnitCount += 1
                        let formattedProgress = String(format: "%.2f", progress.fractionCompleted * 100)
                        task.updateTitle(task.title, subtitle: "Completed \(formattedProgress)%")
                        sleep(1)
                    }
                    
                    if progress.isFinished {
                        print ("i was a good task")
                        task.setTaskCompleted(success: true)
                    } else {
                        print("i was not a good task")
                        task.setTaskCompleted(success: false)
                    }
                }
                
                try? BGTaskScheduler.shared.submit(request)

Apologies if this is clearly stated somewhere and I'm missing it.

If I create a BGContinuedProcessingTaskRequest, register it, and then "do work" within it appropriately reporting progress, and before my task has finished doing all the work it had to do, its expirationHandler triggers...

As a small side comment, you don't actually need to "do" any of the work inside your launchHandler. If you choose, you can just capture the task object (for progress, completion, etc.) and immediately return. See this forum thread for a longer discussion of these issues.

does the task later try again?

No. The idea is that the API is specifically extending foreground time, so it wouldn't really make sense to "resume" it later.

Or does it lose the execution opportunity until the app is next re-launched to the foreground?

In my testing, I never saw my task execute again once expired (which suggests the latter?).

Yes, both of points those are correct.

I was able to easily force this expiry by starting my task, backgrounding my app, then launching the iOS Camera App.

That's actually a little surprising to me. What device are you using? If you haven't already, please file a bug on this and post the bug number once it's filed.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

What happens after BGContinuedProcessingTask "expires"?
 
 
Q