1

我需要下载图像队列。我首先创建了我的操作,然后使用 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

4

1 回答 1

4

这些实际上是在最后一两天修复的:)

继续更新到最新版本的 master,其中包括以下内容:

cc2115e469:进度块现在默认分派到 main,就像 AFNetworking 中的所有其他完成块一样。这应该可以解决围绕 UI 不在那里更新的任何问题。

cac44aeb34:修复了NSBlockOperation发送的问题request。有一个不正确的假设cancelAllHTTPOperationsWithMethod:,即所有操作都是AFHTTPRequestOperation. 唯一的缺点是它不会处理您的批处理操作。为此,您始终可以遍历httpClient.operationQueue.operations并挑选出您想要的那个。

于 2012-03-01T17:19:38.647 回答