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

ben_yIP属地: 上海
字数 94

//信号量

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必须成对出现

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
1人点赞
总资产1共写了369字获得1个赞共2个粉丝

推荐阅读更多精彩内容