3

I want to download files in the background using NSUrlSessionDownloadTask.

To download I need to perform the following:

  1. Perform a POST to get an auth token
  2. Perform a GET to get a download URL using the auth token in the header. The URL I get back includes a temp token in a query parameter. E.g. https://myserver.com/file1?token=abc
  3. Download from the URL I got in the previous step using NSUrlSessionDownloadTask

The token in the download URLs is valid for 3 hours after which I need to perform the process again and get a new URL with a new token.

I checked out NSUrlSessionDownloadTask and I have several problems:

  1. I see there is support for for cert auth and basic auth challenges but not the the auth scheme I use. So, if the download takes more than 3 hours (e.g. because it was interrupted due to no network), I need to re-auth and get a new download URL. Is there a callback that I can use to do the re-auth stuff?

  2. If I manage to re-auth, then I get a new URL. Can I switch URLs in the middle of the NSUrlSessionDownloadTask? In other words, can I continue a download with a different URL? (it is the same URL but the token in the query string is different).

daramasala
  • 3,040
  • 2
  • 26
  • 33

0 Answers0