1

So I have a batch request which is the following code:

[[AHClient sharedClient] enqueueBatchOfHTTPRequestOperationsWithRequests:requestArray progressBlock:^(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations) {


    } completionBlock:^(NSArray * operations){

        dispatch_async(dispatch_get_main_queue(), ^(void){
           //update the UI
        });
    }];

I tried cancelling the request by saving the path of the url in an array and do the following:

for (NSString * urlPath in self.currentRequestArray_){
        [[AHClient sharedClient] cancelAllHTTPOperationsWithMethod:@"GET" path:urlPath];
    }

but it seems that it still goes to the completed block, i.e: updates the UI. Thoughts or suggestions?

Jim
  • 72,985
  • 14
  • 101
  • 108
adit
  • 32,574
  • 72
  • 229
  • 373

1 Answers1

2

In the batch completion block, check that the component operations aren't cancelled, and only perform the action if any of them finished successfully.

    completionBlock:^(NSArray * operations){
      if ([[operations filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"isCancelled == NO"]] count] > 0) {
        dispatch_async(dispatch_get_main_queue(), ^(void){
           //update the UI
        });
      }
    }
dotKwame
  • 181
  • 3
  • 13
mattt
  • 19,544
  • 7
  • 73
  • 84