取消AFNetworking中的批量请求
所以我有一个批处理请求,这是下面的代码:
[[AHClient sharedClient] enqueueBatchOfHTTPRequestOperationsWithRequests:requestArray progressBlock:^(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations) { } completionBlock:^(NSArray * operations){ dispatch_async(dispatch_get_main_queue(), ^(void){ //update the UI }); }];
我试图通过保存在一个数组中的URL的path取消请求,并执行以下操作:
for (NSString * urlPath in self.currentRequestArray_){ [[AHClient sharedClient] cancelAllHTTPOperationsWithMethod:@"GET" path:urlPath]; }
但它似乎仍然去完成块,即:更新用户界面。 想法或build议?
在批量完成块中,检查组件操作是否被取消,并且只有在任何一个操作成功完成时才执行操作。
completionBlock:^(NSArray *操作){ if([[operations filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@“isCancelled == NO”]] count]> 0){ dispatch_async(dispatch_get_main_queue(),^(void){ / /更新用户界面 }); } }