美文网首页
多个异步网络请求结束后再更新UI

多个异步网络请求结束后再更新UI

作者: ben_y | 来源:发表于2017-06-21 18:50 被阅读0次

//信号量

dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);

//创建全局并行

dispatch_group_t group = dispatch_group_create();

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_group_async(group, queue, ^{

          [[ApplicationUtil sharedApplicationUtil] checkVersionIsTheLatest:^(BOOL needUpdate, NSInteger updateType, NSString *updateContent) {

          dispatch_semaphore_signal(semaphore);}];

});

dispatch_group_async(group, queue, ^{

          [self.request getDiscountCouponWithDict:nil success:^(NSDictionary *dictResult) {

                     dispatch_semaphore_signal(semaphore);

          } failed:^(NSInteger code, NSString *errorMsg) {

                     dispatch_semaphore_signal(semaphore);

           }];

});

dispatch_group_async(group, queue, ^{

            [self.request getHomeAdsWithDict:nil success:^(NSDictionary *dictResult) {

                       dispatch_semaphore_signal(semaphore);

              } failed:^(NSInteger code, NSString *errorMsg) {

                        dispatch_semaphore_signal(semaphore);

             }];

});


注:dispatch_semaphore_wait和dispatch_semaphore_signal必须成对出现

相关文章

网友评论

      本文标题:多个异步网络请求结束后再更新UI

      本文链接:https://www.haomeiwen.com/subject/lmmtcxtx.html