有办法取消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];因此,我将“操作”放入"operationQueue“,并可以通过以下方式停止操作:
[operationQueue cancelAllOperations];这只是队列中的一个操作。如果有多个操作,是否有方法显式地停止操作?我猜控制台中出现了以下错误--如果队列被取消,正常吗?
错误的Domain=NSURLErrorDomain代码=-999“操作无法完成。
发布于 2013-12-17 15:51:49
您可以使用:
[operation cancel];这是一个由NSOperation实现的AFNetworking方法。
发布于 2013-12-17 15:52:35
您可以使用它来取消所有操作:
[[httpClient operationQueue] cancelAllOperations];https://stackoverflow.com/questions/20638611
复制相似问题