I’m attempting to add massive recordsdata from iOS to a server utilizing URLSessionConfiguration.background
object and uploadTask
perform.
Issues are trying good til now, however I ponder what truly occurs behind the scene when the app goes into background state. I seemed up the paperwork nevertheless it solely roughly says “the session palms the transfers over to the system”.
What I’ve carried out is simply to initialize a singleton UploadManager
once more in utility(_ utility: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void)
after the duties had been carried out whereas in background. The supervisor occasion creates a brand new URLSession
with the identical identifier inside it.
I assumed I’m simply apparently creating “one other” URLSession occasion once more, however how does it know in regards to the earlier duties and their states to name the suitable delegate strategies?
Does it obtain the data again from course of working by the system?
class UploadManager {
static let shared = UploadManager()
personal var urlSession: URLSession!
personal init() {
let sessionConfig = URLSessionConfiguration.background(withIdentifier: Bundle.important.bundleIdentifier! + ".add")
sessionConfig.networkServiceType = .video
urlSession = URLSession(configuration: sessionConfig, delegate: self, delegateQueue: nil)
}
...
}
extension UploadManager {
func urlSession(_ session: URLSession, job: URLSessionTask, didCompleteWithError error: Error?) {
// do post-upload course of for accomplished jobs
}
}
class AppDelegate: ... {
...
func utility(_ utility: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
NSLog("📙 backgroundURLSession is finished (identifier)")
// simply by instantiating, the suitable completion delegate known as
let supervisor = VideoUploadManager.shared
}
}