我想等待这段代码被执行之前继续,但因为这些块是异步调用,我不知道该怎么办?等待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