我的 ipad 设备中有一个自定义文件夹。我正在使用此代码从自定义相册中获取图像:
self.assetGroups = [[NSMutableArray alloc] init];
// Group enumerator Block
dispatch_async(dispatch_get_main_queue(), ^
{
void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
{
if (group == nil) {
return;
}
if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:@"Ganesh"]) {
[self.assetGroups addObject:group];
[self loadImages];
return;
}
if (stop) {
return;
}
};
// Group Enumerator Failure Block
void (^assetGroupEnumberatorFailure)(NSError *) = ^(NSError *error) {
UIAlertView * alert = [[UIAlertView alloc]
initWithTitle:@"ERROR" message:[NSString stringWithFormat:@"No Albums Available"]
delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
};
// Enumerate Albums
self.library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:assetGroupEnumberatorFailure];
});
要从我的自定义文件夹中检索所有图像,我正在使用这个:
(void)loadImages {
ALAssetsGroup *assetGroup = [self.assetGroups objectAtIndex:0];
NSLog(@"asserts group %@",self.assetGroups);
NSLog(@"ALBUM NAME:;%@",[assetGroup valueForProperty:ALAssetsGroupPropertyName]);
[assetGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop){
if(result == nil) {
return;
}
UIImage *img = [UIImage imageWithCGImage:[[result defaultRepresentation] fullScreenImage]
scale:1.0 orientation:(UIImageOrientation)[[result valueForProperty:@"ALAssetPropertyOrientation"] intValue]];
NSLog(@"image name%@",img);
[arrayOfImage addObject:img];
NSLog(@"arrayOfImage %@",arrayOfImage);
// [imageToAnimate setImage:img];
}];
}
当我使用模拟器但不在设备中运行时,它工作正常:它执行失败块并说没有可用的专辑。