我想等待這段代碼被執行之前繼續,但因爲這些塊是異步調用,我不知道該怎麼辦?等待assetForURL塊完成
NSURL *asseturl;
NSMutableArray *tmpListAsset = [[NSMutableArray alloc] init];
ALAssetsLibrary *library = [[[ALAssetsLibrary alloc] init] autorelease];
NSMutableArray *objectsToRemove = [[NSMutableArray alloc] init];
for (NSDictionary *dico in assetsList) {
asseturl = [NSURL URLWithString:[dico objectForKey:@"assetUrl"]];
NSLog(@"asset url %@", asseturl);
// Try to load asset at mediaURL
[library assetForURL:asseturl resultBlock:^(ALAsset *asset) {
// If asset doesn't exists
if (!asset){
[objectsToRemove addObject:dico];
}else{
[tmpListAsset addObject:[asseturl absoluteString]];
NSLog(@"tmpListAsset : %@", tmpListAsset);
}
} failureBlock:^(NSError *error) {
// Type your code here for failure (when user doesn't allow location in your app)
}];
}
這是一個僅鏈接的答案,應該通過包括源文章中的相關代碼和現代化(因爲這個答案現在是4歲)來改進。 – brandonscript
鏈接被破壞... – diegomen