I am creating a new NSURLSession with the following configurations
if (!self.session) {
NSURLSessionConfiguration *config = [NSURLSessionConfiguration backgroundSessionConfiguration:[self uniquieIdentifier]];
config.discretionary = NO;
self.session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:[NSOperationQueue mainQueue]];
}
and after clicking the button, I try to stop all current download tasks.
[[[self session] delegateQueue] setSuspended:YES];
[[self session] invalidateAndCancel];
However, I get the answers in the didFinishDownloadingToURL delegate method, and I'm sure no new sessions or load task are created after that. How to stop all tasks?
source
share