美文网首页
多个网络请求结束后,进行下一步操作

多个网络请求结束后,进行下一步操作

作者: 三十一_iOS | 来源:发表于2016-04-19 21:46 被阅读464次


dispatch_group_t serviceGroup = dispatch_group_create();

    // Start the first service
    dispatch_group_enter(serviceGroup);

    NSLog(@"开始任务1");


    
    [YunisHttpCommunication getWithUrlString:@"http://iappfree.candou.com:8080/free/applications/limited?currency=rmb&page=1" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"完成任务1");

        dispatch_group_leave(serviceGroup);

        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error == %@",error);
        
    }];
    // Start the second service
    dispatch_group_enter(serviceGroup);
    NSLog(@"开始任务2");

    [YunisHttpCommunication getWithUrlString:@"http://iappfree.candou.com:8080/free/applications/limited?currency=rmb&page=1" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"完成任务2");

        dispatch_group_leave(serviceGroup);
        
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error == %@",error);
        
    }];
    
    dispatch_group_notify(serviceGroup,dispatch_get_main_queue(),^{
        
        NSLog(@"完成任务1、2,进行后续操作");
    });

输出结果:

Paste_Image.png

未验证!!!!

dispatch_async(concurrent_queue, ^{ 
        NSLog(@"---并发任务1---");
});

dispatch_async(concurrent_queue, ^{
           NSLog(@"---并发任务2---");
});
dispatch_barrier_async(concurrent_queue, ^{ 
    dispatch_async(dispatch_get_main_queue(), ^{
           NSLog(@"---所有并发任务结束后回到主线程刷新---"); 
  });
});

2016/10/31 更新 哈哈哈哈,今天终于碰到这个问题了!!


        dispatch_group_t serviceGroup = dispatch_group_create();
        
        
        //退订 已经开通 2、3、5元体验包 不关心结果 FUCK 但是需要等通讯全部返回才开通87 套餐包
        [self.closePackgeIDArray enumerateObjectsUsingBlock:^(NSString  *obj, NSUInteger idx, BOOL * _Nonnull stop) {
            dispatch_group_enter(serviceGroup);
            [PackgeModel operatingUserPackgeWithId:obj operType:PackgeOperatingType_close handel:^(BOOL sucess, NSString *errStr) {
                dispatch_group_leave(serviceGroup);
            }];
        }];
        //开通87
        
        dispatch_group_notify(serviceGroup,dispatch_get_main_queue(),^{
            [PackgeModel operatingUserPackgeWithId:ProductId
                                          operType:PackgeOperatingType_open
                                            handel:handel];
        });

相关文章

网友评论

      本文标题:多个网络请求结束后,进行下一步操作

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