Reputation: 9262
It is possible to receive progress updates about a URLSessionTask
by implementing the URLSessionDataDelegate.urlSession(_:dataTask:didReceive:)
delegate method, and using the delegate-style "task, task.resume()" style of invocation.
With the Combine flavor of the API, this does not appear to be possible. Using URLSession.dataTaskPublisher(for:)
returns a publisher that publishes the (Data, URLResponse)
tuple upon completion, but never invokes the delegate method. In that way, it is very similar to the URLSession.dataTask(with:completionHandler:)
method, which invokes completionHandler
with the final result, and not in-process Progress
reports.
Am I missing any API or pattern to allow progress reporting, or does the Combine flavor of URLSession task handling not offer a way to retrieve progress?
Upvotes: 1
Views: 1060
Reputation: 534893
No, you're not missing anything. To retrieve the progress information you would need to construct your own Future and not use the built-in data task publisher.
Upvotes: 5