I am using NSURLSession + NSURLDownloadTask with completionHandler:
[session downloadTaskWithURL:downloadURL completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error)
it works nice.
But when I want to track download in a progressBar I am running into problems. I am trying to use NSURLSessionDownloadDelegate to track loading. With the upper completionHandler it is never called?!
Using:
NSURLSessionDownloadTask *downloadTask =
[session downloadTaskWithURL:downloadURL];
will call the delegates.
Is there any way to use completionHandler AND delegates?
Or any other way to track download while using completionHandler?
To employ the didWriteData
method of the NSURLSessionDownloadDelegate
, you sadly have to use the rendition of downloadTaskWithURL
without the completionHandler
and then implement your own URLSession:downloadTask:didFinishDownloadingToURL:
to perform those actions you otherwise would have done in the completion handler.
This is a little annoying (especially since the NSURLSessionDownloadDelegate
is set at the session object), but it's how it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With