我需要下载图像队列。我首先创建了我的操作,然后使用 AFNetworking 的“入队”方法添加它们。
我有 2 个问题:1) 我没有为队列工作的进度条(我让它与自定义操作队列一起工作) 2) 我没有找到在需要时停止队列的解决方案
我创建了第一个操作来批处理并在数组中添加主题:
while ((dict = [enumerator nextObject]))
{
NSMutableURLRequest *request = [[MyHTTPClient sharedClient] requestWithMethod:@"GET" path:@"ws/webapp/services/pull_image" parameters:dict];
AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:request
imageProcessingBlock:nil cacheName:nil
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image)
{
NSLog(@"image : %@", [image description]);
// process images
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error)
{
// manage errors
}];
[operations addObject:operation];
}
然后,我将操作排入队列:
[[MyHTTPClient sharedClient] enqueueBatchOfHTTPRequestOperations:operations
progressBlock:^(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations)
{
float percentDone = ((float)((int)numberOfCompletedOperations) / (float)((int)totalNumberOfOperations));
[delegate syncServicesController:self updateProgressView:percentDone];
}
completionBlock:^(NSArray *operations)
{
//
}];
因此,进度下载不起作用。但是我可以看到 numberOfCompletedOperations 的进度...?1,2,3,4,5...我是否需要在主线程中强制刷新进度视图?
当我试图停止网络任务时:
- (void)cancelAllRequests
{
[[MyHTTPClient sharedClient] cancelAllHTTPOperationsWithMethod:@"GET" path:@"ws/webapp/services/pull_image"];
}
我不明白如何停止请求队列...这似乎可行,但我有这个错误:-[NSBlockOperation request]: unrecognized selector sent to instance 0x16f54c70