4

I use NSURLSession downloadTaskWithURL: to download a file, and use NSURLSessionDownloadTask cancelByProducingResumeData: to produce an NSData and save it to a local temp file.

Then I want to resume the download task by using NSURLSession downloadTaskWithResumeData:.

There's a problem, the URL I used to download the file is a temp url, I need to request a new URL to download the same file. After using downloadTaskWithResumeData: , it helps me to create a NSURLSessionDownloadTask with the same URL as before.

How can I replace the URL with the new URL that I newly request? Or how can I change the HTTP Request of this NSURLSessionDownloadTask?

How do you deal with the situation that resume a NSURLSessionDownloadTask with a different URL?

I'm thinking about to get the .tmp file that NSURLSession downloaded, and set the Range in HTTP Header, then write to this file with the new temp URL.

Amztion
  • 41
  • 5

1 Answers1

0

I don't believe that we can resume download if the path of the resource has been modified.

According to 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

Also as we see, there is no way we can modify URL programmatically while resuming a download. We just have an option to provided the partially downloaded data.

NSPratik
  • 4,714
  • 7
  • 51
  • 81