I try to download a zip-archive using NSURLSessionDataTask
.
I am aware that there is a NSURLSessionDownloadTask
, but the point is I want a didReceiveData
callback (to show the progress).
The code is:
NSURLRequest *request = [NSURLRequest requestWithURL:@"..."
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSOperationQueue *myQueue = [NSOperationQueue new];
myQueue.underlyingQueue = dispatch_get_main_queue();
NSURLSession *session = [NSURLSession sessionWithConfiguration:config
delegate:self
delegateQueue:myQueue];
NSURLSessionDataTask* task = [session dataTaskWithRequest:request
completionHandler:^( NSData *data, NSURLResponse *response, NSError *error){ ... }
[task resume];
My class conforms to NSURLSessionDataDelegate
.
When I call the method, after several seconds debugger goes to completionHandler with nil
data and nil
error.
What am I doing wrong?
I also tried:
- calling without completionHandler, then debugger goes to
didReceiveResponse
callback with 200 response and that's all. - using
[NSOperationQueue new]
for the queue - using
[NSURLSession sharedSession]
- didn't get any response - using
[NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier: @"..."]
- falls saying that I can't use a completionHandler, but without it - also no response.