I have this scenario in my app:
I have to execute 2 block of code repeatedly for N times.
in the first block I have to do a network call with Alamofire (I call a HTTP service). this call returns data and in this data there is a image path that I have to download on device
in the second block I have to download the image and then save it on device
After this start over again for N times.
My problem is that the user can have app in background and I would to like that this process continues when app is in background too.
For this reason, after the Alamofire call, I insert this code for download image:
let config = URLSessionConfiguration.background(withIdentifier: "XXXXXX.XXXX")
let session = URLSession(configuration: config, delegate: self, delegateQueue: OperationQueue())
let url = URL(string: "testurl")
let task = session.downloadTask(with: url!)
task.resume()
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {
//save image on device and I recall Alamofire for the next call
}
My problem is this: this process doesent execute when app goes in background. What I'm wrong?