In my project, I start a NSURLSessionDataTask
to check the header of a request, and if they're right, I turn the request into a download or I just discard it:
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler
{
if (XYZ) {
completionHandler(NSURLSessionResponseCancel);
}
else {
completionHandler(NSURLSessionResponseBecomeDownload);
}
}
}
However, I am incurring into a problem: once the session is turned into NSURLSessionDownloadTask
, sometimes nothing happens and - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location
isn't called at all, and - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
either.
What's happening here? Does it make sense?!
––– EDIT –––
Apparently this solves the problem?
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask
{
// Resume the Download Task manually because apparently iOS does not do it automatically?!
[downloadTask resume];
}