Parsing the resume data to get the file location

I am using the URLSessionDownloadTask to download files and want the ability to pause the downloads. I want to use downloadTask.cancel(byProducingResumeData:) to achieve this and get the partially downloaded data.

I want to get the actual file data from this plist but there is no straightforward way to do this. I see that we have a string with .tmp file extension in the plist (For e.g: CFNetworkDownload_yBD90c.tmp) and want to use that value to construct the path in tmp folder. I have seen in few discussions that the structure of this plist is not a constant and has gone though revisions in the past.

Can I rely on this way to get the actual data from the plist?

Alternatively, can anyone suggest other approach for this? (as I can not use the resume data directly since the request gets modified and this will be rejected by the server due to security reasons)

Replies

Can I rely on this way to get the actual data from the plist?

No. The resume data is opaque and you can’t rely on its format in any way. That format has changed in the past and it wouldn’t surprise me if it changed again in the future.

Alternatively, can anyone suggest other approach for this?

AFAIK there’s no good way to do this.

In the short term I’d talk with your server folks to see if they can make resume work out of the box. If they’re concerned about security, they could issue an authentication challenge to which your delegate can respond.

In the longer term, you’re not the first person to hit this and it’d be nice if URLSession had a ‘gimme what you got’ API that takes a resume data blob and returns the content, if any, that is available. If you’d like to see such support added in the future, I encourage you to file an enhancement request describing your requirements.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"