From the doc it looks like uploading a file is a good use case for using beginBackgroundTaskWithExpirationHandler
. I've found that using
let uploadTask = session.uploadTask(with: request as URLRequest, fromFile: file)
uploadTask.resume()
will already run while the app is backgrounded (I'm getting upload progress pings for a while). Additionally I can set the URLSession to be backgrounded:
let config = URLSessionConfiguration.background(withIdentifier: "uploads")
session = URLSession(configuration: config, delegate: self, delegateQueue: nil)
So what is the advantage of using beginBackgroundTaskWithExpirationHandler
? Will it extend the time I've to finish my upload? If so can I know by how much (didn't see anything about this in the doc)? Or is it just that I'll get pinged before the app stops? Should I use it in combination with a background URLSession?
Additionally the docs says that the handler will be called shortly before the app’s remaining background time reaches 0 Does it mean that the app will be terminated after that? ie can I assume that the next call will be application:didFinishLaunchingWithOptions
or can it be applicationDidBecomeActive
?