Background Task Ends Too Early
Spot why a background upload gets killed when the app moves to the background state.
Codeswift
func applicationDidEnterBackground(_ application: UIApplication) {
let taskID = application.beginBackgroundTask(withName: "Upload") {
// expiration handler
}
DispatchQueue.global().async {
self.uploadPendingData() // network work, takes several seconds
}
application.endBackgroundTask(taskID)
}What is the bug in this background-state handling code?