博客> 多个网络请求都完成之后返回
多个网络请求都完成之后返回
2017-10-18 02:41 评论:0 阅读:155 李方建
小技巧

dispatch_group_t group = dispatch_group_create(); dispatch_queue_t serialQueue = dispatch_queue_create("com.wzb.test.www", DISPATCH_QUEUE_SERIAL); dispatch_group_enter(group); dispatch_group_async(group, serialQueue, ^{ // 网络请求一 [WebClick getDataSuccess:^(ResponseModel model) { dispatch_group_leave(group); } failure:^(NSString err) { dispatch_group_leave(group); }]; }); dispatch_group_enter(group); dispatch_group_async(group, serialQueue, ^{ // 网络请求二 [WebClick getDataSuccess:getBigTypeRM onSuccess:^(ResponseModel model) { dispatch_group_leave(group); } failure:^(NSString errorString) { dispatch_group_leave(group); }]; }); dispatch_group_enter(group); dispatch_group_async(group, serialQueue, ^{ // 网络请求三 [WebClick getDataSuccess:^{ dispatch_group_leave(group); } failure:^(NSString *errorString) { dispatch_group_leave(group); }]; });

// 所有网络请求结束后会来到这个方法
dispatch_group_notify(group, serialQueue, ^{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        dispatch_async(dispatch_get_main_queue(), ^{
            // 刷新UI
        });
    });
});
收藏
0
sina weixin mail 回到顶部