【发布时间】:2013-12-17 15:49:28
【问题描述】:
有没有办法取消 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 cancelAllOperations];
这只是队列中的一项操作。如果有多个,有没有办法显式停止操作?我猜控制台中出现以下错误 - 如果队列被取消是否正常?
Error Domain=NSURLErrorDomain Code=-999 "操作无法完成。
【问题讨论】:
标签: ios afnetworking-2