在AFNetworking中取消批量请求 [英] Cancelling batch request in AFNetworking

查看:153
本文介绍了在AFNetworking中取消批量请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个批处理请求,它是以下代码:

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
        });
    }];

我尝试通过保存数组中url的路径来取消请求,并执行以下操作: / p>

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];
    }

但它似乎仍然进入已完成的块,即:更新UI。想法或建议?

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

推荐答案

在批处理完成块中,检查组件操作是否未被取消,只执行操作如果其中任何一个成功完成。

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
        });
      }
    }

这篇关于在AFNetworking中取消批量请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆