Asynchronous NSURLConnection and NSOperation - Cancel

I want to cancel all requests. This is how I create an asynchronous connection:

[NSURLConnection sendAsynchronousRequest:echo queue:self.queue completionHandler:^(NSURLResponse *respone, NSData *data, NSError *error){

Then I use this method:

-(void)cancelAllRequests
{
    NSLog(@"%@",self.queue.operations);
    [self.queue cancelAllOperations];
    [self.queue waitUntilAllOperationsAreFinished];
}

to cancel all requests.

Which actually does nothing but change BOOL to YES.

So how should I cancel the asynchronous connection?

+5
source share
2 answers

You cannot cancel scheduled connections using sendAsynchronousRequest. The queue you are talking about is used only to schedule the completion handler.

If you need full control over NSURLConnection, you will have to implement it NSURLConnectionDelegateyourself. An example implementation can be found at https://gist.github.com/3794804

+5
source

, ( ).

NSOperationQueue maxNumberOfConcurrentOperations 1 ( ).

, cancelAllOperations , , .

+1

All Articles