2012-05-14 40 views
1

所以我有一個批量要求其爲以下代碼:取消批處理請求在AFNetworking

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


    } completionBlock:^(NSArray * operations){ 

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

我試圖通過保存的URL的路徑在陣列中取消該請求,並執行以下操作:

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

但它似乎仍然去完成的塊,即:更新用戶界面。想法或建議?

回答

2

在批處理完成塊中,檢查組件操作是否未取消,並且只有在任何操作成功完成時才執行操作。

 
    completionBlock:^(NSArray * operations){ 
     if ([[operations filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"isCancelled == NO"]] count] > 0) { 
     dispatch_async(dispatch_get_main_queue(), ^(void){ 
      //update the UI 
     }); 
     } 
    }