Cancel Pause Resume On-Demand Resource

I have everything associate with on-demand resources working correctly in my application with the exception of the ability to cancel, pause or resume downloading ODR content. Using Xcode 9.4.1 with iOS 11.4 target, the cancel, pause, etc. IBAction is called when a tap occurs, but the progress bar continues unabated. The ODR progress observer completes too. I've seen code like this:


class ODRManager {

var myCollectionRequest: NSBundleResourceRequest?


@IBAction func cancelLoadingOnDemandResource(_ sender: UIButton) {

guard let myCurrentRequest = myCollectionRequest else { return }

myCurrentRequest.progress.cancel()

}

}


But such code doesn't cancel/pause the NSBundleResourceRequest. I found a radar report dated Jan. 12, 2016 indicating the same problem. Is it possible to cancel, pause or resume a NSBundleResourceRequest download? If so, how is it done?


Thank you.

  • Hi,

    Did you find any solution for Pause the progress?

    I'm Facing the same issue with On-Demand Resource.

    Thanks in Advance.

Add a Comment

Replies

I found a radar report dated Jan. 12, 2016 indicating the same problem.

And that bug number was?

Share and Enjoy

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

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

Thank you for your reply. Here is the radar report I found.


Open Radar

Community bug reports


NSBundleResourceRequest are not pausable

Originator:borissotillos
Number:rdar://24151061Date Originated:12-Jan-2016 07:02 PM
Status:openResolved:
Product:tvOS SDKProduct Version:9.1 (13U85)
Classification:Reproducible:100%
 Boris Sotillos 12-Jan-2016 07:02 PM  
Summary: The NSBundleResourceRequest::progress::pause/NSBundleResourceRequest::progress::resume methods are not working. pausingHandler and resumingHandler are called, but the actual download is left unaffected (the progress is still getting called).
For the NSBundleResourceRequest, progress::isPausable returns "NO". I guess this means that there is no way to pause a download.
I would expect downloads to be pausable.
2016-01-12 17:50:18.210 ******[1033:2669647] 1 pausable = 0
2016-01-12 17:50:18.214 ******[1033:2669647] 2
2016-01-12 17:50:18.226 ******[1033:2669666] conditionallyBeginAccessingResourcesWithCompletionHandler downloadRequired = 1
2016-01-12 17:50:19.215 ******[1033:2669647] 3
2016-01-12 17:50:19.215 ******[1033:2669647] 4 downloadRequired = 1 2016-01-12 17:50:19.217 ******[1033:2669647] 6
2016-01-12 17:50:25.224 ******[1033:2669647] 7 pausing
2016-01-12 17:50:25.224 ******[1033:2669666] pausingHandler 2016-01-12 17:50:25.225 ******[1033:2669647] 8 finished = 0
2016-01-12 17:50:53.982 ******[1033:2669672] beginAccessingResourcesWithCompletionHandler
2016-01-12 17:51:05.226 ******[1033:2669647] 9 finished = 1
Steps to Reproduce:
I have attached an xcode project. run it, inspect console log, read description above
Expected Results: I would expect downloads to be pausable. I know that NSBundleResourceRequest::progress::isPausable returns NO.
Actual Results: Downloads are not pausable. And the completion handler gets called even after the release
Version: 9.1 (13U85)
Notes: Configuration: ATV using LAN Attachments: '******_pause.zip' was successfully uploaded. ====================================================================================================================================
Boris Sotillos 28-Jan-2016 04:29 PM Retested with tvOS 9.2 beta 2 (12Y5189e), compiled on Xcode 7.3 beta (7D129n)
Same behaviour. Still can't pause a download. progress::isPausable returns "NO".

Thanks for that. That bug (r. 24151061) is clearly about the ability to pause and resume a request, and reading through the analysis so far it seems that the developer’s conclusion is correct: Pause and resume don’t work. Moreover, they don’t work because they are simply not wired up )-: We’re using this bug as a request to add that support.

The only remaining issue is cancellation. Reading through other bug reports it seems that cancellation should work. Can you re-test that and let me know what you see?

Share and Enjoy

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

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

Thank you for the opportunity to reply. Here's what I've experienced as of July 18, 2018:


Using Xcode 10.4.1 for iOS 10.3 through 11.4, it is possible to cancel an on-demand resource download. If a subsequent attempt to download the ODR content is made, that download succeeds. For the benefit of others who might read this, cancelling the download will cause an error. It's possible to capture the error by checking the error code for NSUserCancelledError. As per your comment, attempting to pause or resume a download is currently inoperative.

Hello -
I too am finding request.progress.cancel() has no effect on the request.beginAccessingResources call. The only change that happens is once the download is complete the request.progress.isCancelled is true, but it's clear the entire downloaded completed.
How do I actual cancel the download so the user could interact with downloadable content again?
Michelle

Did you find any solution for Pause the progress?

My understanding is that there’s still no way to pause and resume ODR requests (r. 24151061).

Share and Enjoy

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

This is still true as for now 211026.

Behaviors:

  • If the progress is canceled, the bundle resource request will still finish downloading the resource file, but completes with a canceled error (NSUserCancelledError). If the same resource is requested again, isResourceAvailable will be true and the resource is available instantly.
  • No way to pause or resume the request/progress