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.
You can use:
[operation cancel];
This is an NSOperation method that's implemented by AFNetworking.
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