在iOS开发中,对于多线程,大多数开发者使用苹果提供的简单的GCD,
频繁的使用GCD,并发队列并不会去管理最大并发数,无限制提交任务给并发队列,会给性能带来问题。
for循环中使用block,并且需要block执行完成后继续执行后续代码
dispatch_group_t group = dispatch_group_create();
for (UIImage *image in imageArray) {
dispatch_group_enter(group);
[image_ jkr_fastCompressToDataLength:500000 withBlock:^(NSData *data) {
dispatch_group_leave(group);
}];
}
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
NSDictionary *args = @{@"success":@true,
@"error":@"",
@"data":baseList};
[self.jsBridge postNotificationJavaScript:[self returnResult:self.callbackMap[@"device.selectPhotos"] args:args] toWebView:self.webView];
});
网友评论