(IOS)单个页面多个网络请求的情况,需要监听所有网络请求结束后刷新UI

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

        });

    });

});

你可能感兴趣的:((IOS)单个页面多个网络请求的情况,需要监听所有网络请求结束后刷新UI)