NSURLSessionResponseBecomeDownload和NSURLSessionDownloadTask委托问题

时间:2015-11-08 04:19:01

标签: objective-c nsurlsession nsurlsessiondownloadtask ios9.1

在我的项目中,我启动NSURLSessionDataTask来检查请求的标头,如果它们是正确的,我会将请求转为下载,或者我只是丢弃它:

- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler
{
        if (XYZ) {
            completionHandler(NSURLSessionResponseCancel);
        }
        else {
            completionHandler(NSURLSessionResponseBecomeDownload);
        }
    }
}

但是,我遇到了一个问题:一旦会话变为NSURLSessionDownloadTask,有时没有任何事情发生,- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location根本没有被调用,- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error也是。

这里发生了什么?这有意义吗?!

---编辑---

显然这解决了这个问题?

- (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];
}

0 个答案:

没有答案