所以我有一个批处理请求,它是以下代码:
[[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];
}
但它似乎仍然进入已完成的块,即:更新UI。想法或建议?
答案 0 :(得分:2)
在批处理完成块中,检查组件操作是否未被取消,只有在其中任何一个成功完成时才执行操作。
completionBlock:^(NSArray * operations){ if ([[operations filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"isCancelled == NO"]] count] > 0) { dispatch_async(dispatch_get_main_queue(), ^(void){ //update the UI }); } }