【发布时间】:2014-02-18 23:46:36
【问题描述】:
目前我正在尝试执行一些异步和并发任务,并且我正在使用 Azures blob 上传所有图像,但值得关注的是,对于每个 blob,我需要获取一个 SASURL 然后上传图像。另一个方面是我希望完成上传图像的所有操作,从而将最终上传发送到数据库。虽然我可以提前将操作发送到数据库,而无需确认图像完成,但我只是想确保操作确实完成。
下面是 SASURL 块的代码。
- (void)storageServiceBlob:(NSArray*)images
{
StorageService *storageService = [StorageService getInstance];
NSLog(@"%@",[storageService containers]);
NSLog(@"%@",[storageService blobs]);
for (int i = 0; i < [images count]; i++) {
NSString *file_name = [images objectAtIndex:i];
NSString *result = [self imageName:file_name];
NSLog(@"Final: %@", result);
[storageService getSasUrlForNewBlob:result forContainer:@"misccontainer" withCompletion:^(NSString *sasUrl) {
NSLog(@"%@",sasUrl);
[self postBlobWithUrl:sasUrl Image:[images objectAtIndex:i]];
}];
}
}
我想以某种方式在组中使用 gcd 来确定在组中调用所有完成块之后,它会执行 Post 方法。无论如何在gcd中这样做吗?
【问题讨论】:
-
您可以在完成块中保留一个运行总计,并在
completedBlocks == [images count]时运行您的邮政编码。
标签: ios objective-c cocoa-touch cocoa