1

I use NSURLSessionDownloadTask to download a file from server, it is run in a background session. I want to save resume data to resume the download when the app is terminated. However, the call of cancelByProducingResumeData always returns null. I cannot figure out the issue, cause I used to do a sample of resumable download task successful before. Does anybody get the same issue?

LongNV
  • 892
  • 9
  • 21
  • Something that hit me, so worth asking: have you checked that when you call cancel the state of task is not "cancelling" or "complete"? This can happen for example if the session's invalidateAndCancel is called. Or maybe also during shutdown of the app? During shutdown of the app I handle this more appropriately taking the resume data from the error you receive in `URLSession:task:didCompleteWithError:`. – Matteo Mecucci May 16 '18 at 11:49

1 Answers1

6

Do you know if the request satisfies the criteria outlined in the documentation for the cancelByProducingResumeData method?

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
Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • I already considered this one, but not sure whether it satisfied all of the conditions. I download file from dropbox public folder. I think dropbox server supports all of those. – LongNV Jun 14 '14 at 01:56
  • 2
    @LongNV You could watch a request with [Charles](http://www.charlesproxy.com) and confirm the response's headers... – Rob Jun 14 '14 at 08:15
  • I am able to handle it now, btw thanks for great tool – LongNV Jun 15 '14 at 05:23