Pregunta

Necesito descargar una cola de imágenes. Creé primero mis operaciones, luego agregué el método de "enquema" de AFNetworking.

Tengo 2 problemas: 1) No tuve la barra de progreso trabajando para la cola (y lo tengo trabajando con una cola de operación personalizada) 2) No encontré la solución para detener la cola cuando quiero

He creado primeras operaciones para lotes y agregar tema en una matriz:

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

Entonces, enmalto las operaciones:

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

Entonces, la descarga de progreso no funcionó. Pero puedo ver el progreso de las operaciones de númeroFCompleto ...?1,2,3,4,5 ... ¿Necesito forzar la actualización de la vista de progreso en el hilo principal?

y cuando intenté detener las tareas de red:

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

}

No entiendo cómo detener la cola de las solicitudes ... Esto parece que funciona, pero tengo este error: - [Solicitud de NSBLOCOTRICIO]: selector no reconocido enviado a instancia 0x16f54c70

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top