NSMutableArray*array = [NSMutableArrayarray];
dispatch_group_t dispatchGroup =dispatch_group_create();
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0);
for(int i =0; i < assetArray.count-1; i++) {
dispatch_group_enter(dispatchGroup);
UIImage*asset = [assetArrayobjectAtIndex:i];
dispatch_group_async(dispatchGroup, queue, ^{
[self uploadAsset:assetsuccess:^(NSString*url) {
@synchronized(array) {
[arrayaddObject:url];
}
dispatch_group_leave(dispatchGroup);
}failure:^{
dispatch_group_leave(dispatchGroup);
if(failure) {
failure();
}
}];
});
NSLog(@"多线程发送请求index = %d",i);
}
dispatch_group_notify(dispatchGroup,dispatch_get_main_queue(), ^{
if(success) {
success([arraycopy]);
}
});
网友评论