I want to cancel all requests. Here is how I'm creating asynchronous connection:
[NSURLConnection sendAsynchronousRequest:echo queue:self.queue completionHandler:^(NSURLResponse *respone, NSData *data, NSError *error){
I then use this method:
-(void)cancelAllRequests
{
NSLog(@"%@",self.queue.operations);
[self.queue cancelAllOperations];
[self.queue waitUntilAllOperationsAreFinished];
}
to cancel all requests.
Which actually doesn't do anything except changing a BOOL to YES.
So how I'm supposed to cancel an asynchronous connection?
You can't cancel connections scheduled using sendAsynchronousRequest
. The queue you're referring to is only used for scheduling the completion hander.
If you want full control of the NSURLConnection
, you'll have to implement the NSURLConnectionDelegate
yourself. An example implementation can be found on https://gist.github.com/3794804
What you could do is put Synchronous requests into an Operation (using a block).
The set the NSOperationQueue maxNumberOfConcurrentOperations to 1 (so they run one at a time).
Then if you run cancelAllOperations on the queue it will stop any operations that haven't run yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With