當前我正在嘗試執行一些異步和併發任務,並且我使用Azure blob來上傳所有圖像,但是擔心的是,對於每個blob,我需要獲取SASURL,然後上傳圖像。另一方面,我希望完成的圖像的所有操作都要上傳,並最終上傳到數據庫。雖然我可以提前將操作發送到數據庫,但沒有完成對圖像的確認,但我只是想確保操作完成。for循環中的完成塊
下面是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]'時,您可以在完成塊中保持運行總數並運行您的郵政編碼。 – Linuxios