AFNETWORKING +キュー+キャンセル操作で画像をダウンロードしてください

StackOverflow https://stackoverflow.com/questions/9516911

  •  14-11-2019
  •  | 
  •  

質問

画像のキューをダウンロードする必要があります。 私は最初に私の操作を作成した後、Afnetworkingの "Enqueue"メソッドでそれらを追加しました。

私は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) 
      {
        //
      }];
.

だから、進行状況のダウンロードは機能しませんでした。 しかし、私はNunderOfCompletedOperationsの進行状況を見ることができます...?1,2,3,4,5 ...メインスレッドの進行状況ビューのリフレッシュを強制する必要がありますか?

ネットワークタスクを停止しようとしたとき:

- (void)cancelAllRequests
{
  [[MyHTTPClient sharedClient] cancelAllHTTPOperationsWithMethod:@"GET" path:@"ws/webapp/services/pull_image"];

}
.

要求のキューを停止する方法を理解していません...これは機能しますが、このエラーがあります。 - [NSBlockOperation Request]:インスタンス0x16F54C70

役に立ちましたか?

解決

These were actually just fixed in the last day or two :)

Go ahead and update to the latest version of master, which includes the following:

cc2115e469: Progress blocks now dispatch to main by default, just like all of the other completion blocks in AFNetworking. This should fix any issues around the UI not updating there.

cac44aeb34: Fixes that problem with NSBlockOperation being sent request. There was an incorrect assumption baked into cancelAllHTTPOperationsWithMethod: that all operations were AFHTTPRequestOperation. The only downside is that it will not handle your batched operations. For that, you can always iterate through httpClient.operationQueue.operations and pick out the one you want.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top