我的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];
}];
}
当我使用模拟器但不在设备中运行时它工作正常:它执行失败块并说没有相册可用。
答案 0 :(得分:0)
它的工作正常。我已经关闭了我的位置服务,因为现在无法访问我的媒体工作正常。