NSURLSession cancelByProducingResumeData vs. 302 redirects

The documentation for NSURLSession cancelByProducingResumeData states:


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


What if the original URL request responds with a 302 (temporary redirect)?


In my testing, it seems that if my server responds a 302 (temporary redirect), then NSURLSession cancelByProducingResumeData does not produce resume data.


Is this the expected behavior?

In my testing, it seems that if my server responds a 302 (temporary redirect), then NSURLSession cancelByProducingResumeData does not produce resume data.

Does this happen in a background session, a standard session, or both?

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I am only using background sessions. The problem seems to reproduce in iOS 8.2. (Tested in an iPhone 4s simulator.)


The good news (for me) is that I just noticed that I _am_ receiving resume data for 302 redirects on iOS 9.0 b4 on both simulator and a real iPhone 6 device.


So perhaps it's a limitation of older versions of iOS that's fixed in more recent versions of iOS.

So perhaps it's a limitation of older versions of iOS that's fixed in more recent versions of iOS.

Sounds likely.

You may be able to work around this on pre-iOS 9 systems by issuing the initial request in a standard session, stopping that request once you get the redirect, and then issuing the redirected request in your background session. This will work as long as the server that issues the redirect doesn't have some sort of timeout on the redirect.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
NSURLSession cancelByProducingResumeData vs. 302 redirects
 
 
Q