Authentication in `NSUrlSessionDownloadTask`

I want to download files in the background using NSUrlSessionDownloadTask

.

To download, I need to do the following:

  • POST to get an authorization token
  • Do a GET to get the download url using the auth token in the header. The url I am returning includes the temp token in the request parameter. For example.https://myserver.com/file1?token=abc

  • 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 do this process again and get a new url with a new token.

I have checked NSUrlSessionDownloadTask

and I have several problems:

  • I see there is support for cert auth and basic auth tasks, but not for the auth scheme I am using. Thus, if the download takes more than 3 hours (for example, because it was interrupted due to lack of network), I need to restart and get a new download URL. Is there a callback that I can use for reuse?

  • If I manage to re-login, I get a new URL. Can I switch urls in the middle NSUrlSessionDownloadTask

    ? In other words, can I continue downloading with a different url? (this is the same URL, but the token in the query string is different).

+3


source to share





All Articles