@归虹尘 看文章内容中的 getA 这个方法
iOS GCD之多个请求顺序执行一、业务场景。 各个方法都是异步,但需要他们顺序执行。如提交信息C(submitC)之前需要获取B(getB),而获取B(getB),则需要先获取A(getA)。getA--...
给所有上传任务增加信号量来判断是否所有任务都已完成。代码如下:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{
dispatch_group_t group = dispatch_group_create();
for (NSInteger index = 0; index < imageDataArray.count; index++) {
dispatch_group_enter(group);
[[LDHttpRequest sharedLDHttpRequest] uploadImage:requestUrl imageData:imageDataArray[index] params:nil parameterOfImage:@"file" success:^(id responseObj) {
if ([responseObj objectForKey:@"url"]) {
NSDictionary *dic = @{
@"fileName":[responseObj objectForKey:@"submittedFileName"],
@"filePath":[responseObj objectForKey:@"url"]
};
@synchronized (result) { //同步锁
result[index] = dic;
}
}
dispatch_group_leave(group);
} fail:^(LocalError *localError, NSError *netError) {
dispatch_group_leave(group);
}];
}
NSMutableArray *fileList = [NSMutableArray array];
//所有任务都完成
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
for (NSDictionary *dic in result) {
if([dic objectForKey:@"filePath"]){
[fileList addObject:dic];
}
}
weakSelf.fileList = fileList;
[self submitAll:loading];
});
});
iOS GCD之多个请求顺序执行一、业务场景。 各个方法都是异步,但需要他们顺序执行。如提交信息C(submitC)之前需要获取B(getB),而获取B(getB),则需要先获取A(getA)。getA--...
Hola,我是 yes。 今年来看了 RocketMQ、Kafka、Dubbo 、Tomcat 的源码,之前也有读者询问过如何读源码,索性就来分享一下。 其实还看了一点点 L...
一、iOS12(Xcode10) 1.1、升级Xcode10后项目报错 不允许多个info.plist Xcode10是默认选中的最新的New Build System(De...
一、业务场景。 各个方法都是异步,但需要他们顺序执行。如提交信息C(submitC)之前需要获取B(getB),而获取B(getB),则需要先获取A(getA)。getA--...