然后我想通过使用NSURLSession downloadTaskWithResumeData:恢复下载任务.
有一个问题,我用来下载文件的URL是临时URL,我需要请求一个新的URL来下载相同的文件.
使用downloadTaskWithResumeData:后,它帮助我创建一个NSURLSessionDownloadTask与以前相同的URL.
如何用我新请求的新URL替换URL?
或者我如何更改此NSURLSessionDownloadTask的HTTP请求?
您如何处理使用不同的URL恢复NSURLSessionDownloadTask的情况?
我正在考虑获取NSURLSession下载的.tmp文件,并在HTTP Header中设置Range,然后使用新的临时URL写入此文件.
解决方法
根据Apple Developer Class Reference:
A download can be resumed only if the following conditions are met:
The resource has not changed since you first requested it
The task is an HTTP or HTTPS GET request
The server provides either the ETag or Last-Modified header (or both) in its response
The server supports byte-range requests
The temporary file hasn’t been deleted by the system in response to disk space pressure
同样如我们所见,我们无法在恢复下载时以编程方式修改URL.我们只能选择提供部分下载的数据.