Asynchronous url requests inside dispatch_async

前端 未结 3 1552
悲&欢浪女
悲&欢浪女 2020-12-28 10:35

I am trying to implement asynchronous url requests in a particular function, I want all these requests to complete and then do a particular action but the action precedes th

3条回答
  •  粉色の甜心
    2020-12-28 11:42

    You can create a dispatch_group_t and then use dispatch_group_notify to execute the updateUIFunction when the previous block of the group finish running, for example:

    dispatch_queue_t fetchQ = dispatch_queue_create("Featured Doc Downloader", NULL);
    dispatch_async(fetchQ, ^{
        dispatch_group_t group = dispatch_group_create();
        dispatch_group_async(group, dispatch_get_global_queue(0, 0), ^{
            [self myAsyncMultipleURLRequestFunction];
        });
        dispatch_group_notify(group, dispatch_get_global_queue(0, 0), ^{
            dispatch_async(dispatch_get_main_queue(), ^{
                [self updateUIFunction];
            });
        });
    });
    

提交回复
热议问题