iOS 多组数据队列上传

尽量把所要调用的函数写成block形式的

示例如下,仅供参考:

//2.创建上传队列——————先取全部数据-----队列单笔上传操作---轮询分批复查————————count<0结束
-(void)createTackAllPsot{
    [self getAllTackDic];
    if (psotArr.count<1) {
        return;
    }
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
    Context.isPosting = YES;
     dispatch_semaphore_t sema = dispatch_semaphore_create(0);
     dispatch_group_t group = dispatch_group_create();
        for (NSDictionary *postDic in psotArr){//创建上传队列
            [[SDKManager shareManager]initTimViewQueryData:@[postDic[@"bizGuid"]] WithResult:^(BOOL result, id resultString) {
                if (result == NO) {//检查是否有 ke上传的影像
                    dispatch_group_enter(group);
                    dispatch_async(dispatch_get_global_queue(0, 0), ^{
                        dispatch_semaphore_t sema2 = dispatch_semaphore_create(0);
                        //数据交易 上传
                        [self yxkjPostTask:postDic withResultData:^(BOOL result, NSString *resultString) {
                            dispatch_semaphore_signal(sema2);
                        }];
                        dispatch_semaphore_wait(sema2, DISPATCH_TIME_FOREVER);
                        dispatch_group_leave(group);
                    });
                }else{
                    dispatch_group_enter(group);
                    dispatch_async(dispatch_get_global_queue(0, 0), ^{
                        dispatch_semaphore_t sema3 = dispatch_semaphore_create(0);
                        [[SDKManager shareManager]uploadImagesData:postDic WithResult:^(BOOL result, id resultString) {
                            if (result) {
                                NSMutableDictionary *newDic = [NSMutableDictionary dictionary];
                                [newDic addEntriesFromDictionary:postDic];
                                [newDic addEntriesFromDictionary:resultString];
                                [self yxkjPostTask:newDic withResultData:^(BOOL result, NSString *resultString) {
                                    dispatch_semaphore_signal(sema3);
                                }];
                            }else{
                                if ([resultString isEqualToString:@"yxkjError"]) {//yxkj上传失败
                                    [self updataTackErrorWithTackId:postDic[@"TaskId"] withErrorString:@"030" withResultData:^(BOOL result, NSString *resultString) {
                                        dispatch_semaphore_signal(sema3);
                                    }];
                                }
                            }
                        }];
                        dispatch_semaphore_wait(sema3, DISPATCH_TIME_FOREVER);
                        dispatch_group_leave(group);
                    });
                }
            }];
            dispatch_group_notify(group, dispatch_get_main_queue(), ^{
                dispatch_semaphore_signal(sema);
            });
            dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
        }
        Context.isPosting = NO;
        [self createTackAllPsot];
    });
   


}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 本文用来介绍 iOS 多线程中 GCD 的相关知识以及使用方法。这大概是史上最详细、清晰的关于 GCD 的详细讲...
    花花世界的孤独行者阅读 525评论 0 1
  • 一:base.h 二:block.h 1. dispatch_block_flags:DISPATCH_BLOCK...
    小暖风阅读 2,505评论 0 0
  • 很久前的总结,今天贴出来。适合看了就用,很少讲解,纯粹用法。 目录 Dispatch Queue dispatch...
    和女神经常玩阅读 704评论 0 3
  • 今夜,我准备去一趟盘丝洞。其实盘丝洞不是个地名,而是一个特别的地名。 一般情况下我很少语无论次的,这种情况出现了我...
    长风18阅读 466评论 3 3
  • 梦想二字是人生中无法逃避的话题,不管是自己心中埋下的一颗小小的种子,还是别人口中茶余饭后的八卦,抑或者成功人士笔下...
    若如晴阅读 702评论 0 2