Background Transfer Service: suspend DownloadTask does not work

Hello I have the following problem. I use a background session and start about 100-200 download tasks.

After some files have been loaded I pause all download tasks as follows:


for (NSURLSessionTask * t in [session manager downloadTasks]) {

[t suspend];

}


The works so far. But after a while the download tasks run simply. Is this due to the background session or should I consider something else.

Accepted Answer

I'm not 100% sure what's going on here. I don't have experience with suspending tasks because… well, see below. If you have a reproducible case, please file a bug, including a small test project that demonstrates the issue. I'd appreciate you posting your bug number here, just for the record.

My question for you is, why are you suspending these tasks? Tasks suspension is rarely used and, when it is, it's mostly used to temporarily disable callbacks as part of some sort of concurrency control system. That's because a suspended task can still be active on the wire; all that the suspend does is prevent it making progress internally, issuing callbacks, and so on.

OTOH, if you're implementing a long-term pause (for example, the user wants to pause a download), you'd be better off calling

-cancelByProducingResumeData:
.

Share and Enjoy

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

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

Ok thank you that has helped me a lot. Unfortunately, you have not indicated in the official documentation, that this feature is to enjoy with caution.

I will then use the method -cancelByProducingResumeData:


I am assuming that my mistake arises from the fact that I have the discretionary Property set.

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:kBackgroundSessionIdentifier];

configuration.discretionary = TRUE;


Many thanks.

Unfortunately, you have not indicated in the official documentation, that this feature is to enjoy with caution.

I doubt this is covered in the docs. As always, if you find the documentation deficient, please do file a bug against it (and post your bug number, just for the record).

I am assuming that my mistake arises from the fact that I have the discretionary Property set.

I don't think that

discretionary
is the root cause of this issue, but rather the fact that you're using a background session.

Share and Enjoy

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

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

Hi Eskimo,


I have the same issue on iOS 9.1 opened a bug #23292348 with a reproducible application.


Thanks,

Israel

Background Transfer Service: suspend DownloadTask does not work
 
 
Q