I use URLSession
and URLSessionDataTask
to get an image from server and display it in an app. I had a look here. It looks like URLSessionDownloadTask
has more options.
Currently I use the following code for getting the image:
let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
guard error == nil else {
completion(error, nil)
return
}
completion(nil, data)
}
task.resume()
I'd like to be able to suspend, cancel and resume the process of getting the image from the server. I see in the documentation that URLSessionDataTask
also has these options. But it's also written for the suspend method of URLSessionTask
that:
A download task can continue transferring data at a later time. All other tasks must start over when resumed.
So my question is: Should I change the implementation to use URLSessionDownloadTask
for getting the images if I need to be able to stop getting the image at some point and resume later without losing the current progress? Thank you in advance.