AFHTTPRequestOperation Cancel Request

Viewed 6214

Is there a way to cancel a AFHTTPRequestOperation? I am using it to download a PLIST for example. So I was planning to have a button to cancel the download or task. Is there a way?

Update:

operationQueue = [NSOperationQueue new];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:myURL] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFPropertyListResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id propertyList) {

    NSLog(@"DONE");        

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    NSLog(@"%@", error);

}
 ];

 [operationQueue addOperation:operation];

So I have put "operation" to "operationQueue" and can stop the operation with:

[operationQueue cancelAllOperations];

This is only one operation in the queue. Is there a way to stop operation explicit if there are more than one? I guess the following error in the console - is it normal if a queue gets cancelled?

Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed.

2 Answers
Related