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