Is there any way to cancel AFHTTPRequestOperation? I use it to load plist. So I had a button to cancel the download or task. Is there any 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 put the “operation” in “operationQueue” and can stop the operation with:
[operationQueue cancelAllOperations]
This is only one operation in the queue. Is there any way to terminate the operation explicitly if there are several? I assume the following error in the console is normal if the queue is canceled?
Error Domain = NSURLErrorDomain Code = -999 "The operation could not be completed.
source
share