Domanda

Ho bisogno di scaricare una coda di immagini. Ho creato prima le mie operazioni, quindi aggiungile con il metodo "Enqueue" di Afnetworking.

Ho 2 problemi: 1) Non avevo la barra dei progressi funzionante per la coda (e lo ho lavorato con una coda di funzionamento personalizzata) 2) Non ho trovato la soluzione per fermare la coda quando voglio

Ho creato le prime operazioni da batch e aggiungere il tema in un array:

  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];
  }
.

Allora, enquequee le operazioni:

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

Allora, il download dei progressi non funzionava. Ma posso vedere i progressi del numero di numeroFompletedoperazioni ...?1,2,3,4,5 ... Devo forzare l'aggiornamento della vista del progresso nel thread principale?

E quando ho provato a interrompere le attività di rete:

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

}
.

Non capisco come interrompere la coda delle richieste ... Questo sembra che funzioni ma ho questo errore: - [NSBLOCKOPERATION RICHIESTA]: selettore non riconosciuto inviato all'istanza 0x16F54C70

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top