Solicitudes de lote AFNetworking: cancela cuando falla la primera

Estoy usando el código AFNetworking para las requestes por lotes. Realmente he copydo y pegado del código de ejemplo, se ve así:

NSMutableArray *mutableOperations = [NSMutableArray array]; for (NSURL *fileURL in filesToUpload) { NSURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"http://example.com/upload" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData [formData appendPartWithFileURL:fileURL name:@"images[]" error:nil]; }]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [mutableOperations addObject:operation]; } NSArray *operations = [AFURLConnectionOperation batchOfRequestOperations:mutableOperation progressBlock:^(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations) { NSLog(@"%lu of %lu complete", numberOfFinishedOperations, totalNumberOfOperations); } completionBlock:^(NSArray *operations) { NSLog(@"All operations in batch complete"); }]; [[NSOperationQueue mainQueue] addOperations:operations waitUntilFinished:NO]; 

Ahora lo que quiero lograr es cancelar todas las demás operaciones en esa queue si falla la primera.

Encontré una solución para 1.0.3 con AFHttpClient pero nada para 2.0.

Algun consejo ?

En lugar de agregar las operaciones al [NSOperationQueue mainQueue] , cree su propia queue de operaciones. Entonces, en tu @interface define una queue:

 @property (nonatomic, strong) NSOperationQueue *networkQueue; 

Luego, instancie una queue:

 self.networkQueue = [[NSOperationQueue alloc] init]; self.networkQueue.name = @"com.domain.app.networkqueue"; // if you want it to be a serial queue, set maxConcurrentOperationCount to 1 // // self.networkQueue.maxConcurrentOperationCount = 1; // // if you want it to be a concurrent queue, set it to some reasonable value // // self.networkQueue.maxConcurrentOperationCount = 4; 

Luego, agregue sus operaciones de networking a esta queue (evitando batchOfRequestOperations ):

 NSOperation *completionOperation = [NSBlockOperation blockOperationWithBlock:^{ NSLog(@"All operations done"); }]; // NSOperation *previousOperation = nil; // if you uncomment dependency code below, uncomment this, too for (NSURL *fileURL in filesToUpload) { NSURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"http://example.com/upload" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData [formData appendPartWithFileURL:fileURL name:@"images[]" error:nil]; }]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; // if you want the operations to run serially, you can also // make each dependent upon the prior one, as well // // if (previousOperation) // [operation addDependency:previousOperation]; // // previousOperation = operation; [completionOperation addDependency:operation]; [self.networkQueue addOperation:operation]; } [self.networkQueue addOperation:completionOperation]; 

Y, por último, si desea cancelar las operaciones, puede hacer lo siguiente:

 [self.networkQueue cancelAllOperations];