有没有办法取消 AFHTTPRequestOperation?例如,我用它来下载 PLIST。所以我打算有一个按钮来取消下载或任务。 有办法吗?
更新:
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];
所以我已经将“operation”放入“operationQueue”并且可以通过以下方式停止操作:
[operationQueue cancelAllOperations];
这只是队列中的一个操作。如果有多个,有没有办法停止显式操作?我猜控制台中出现以下错误 - 如果队列被取消是否正常?
Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed.
最佳答案
您可以使用:
[operation cancel];
这是一个由 AFNetworking 实现的 NSOperation 方法。
关于ios - AFHTTPRequestOperation 取消请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20638611/