ALAssetsLibrary 获取相机胶卷
Posted
技术标签:
【中文标题】ALAssetsLibrary 获取相机胶卷【英文标题】:ALAssetsLibrary get Camera Roll 【发布时间】:2013-03-22 12:17:11 【问题描述】:我使用ALAssetsLibrary
枚举所有资产组
代码如下:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
void (^enumerate)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
if (group == nil)
// enumerated all albums..
// I hot to check if group is Camera Roll ?
;
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:enumerate
failureBlock:nil];
如何检查当前枚举是否为CameraRoll?
编辑:正如我测试的那样,它总是最后一个,使用这个枚举。但我不确定这是否是规则,有没有我遗漏的参考资料?
【问题讨论】:
【参考方案1】:要从相机胶卷中获取照片,请在枚举资产库时使用ALAssetsGroupSavedPhotos
:
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:enumerate
failureBlock:nil];
检测您当前获得的组:
if ([[group valueForProperty:@"ALAssetsGroupPropertyType"] intValue] == ALAssetsGroupSavedPhotos)
NSLog(@"Camera roll");
【讨论】:
我看到了这个解决方案,但我需要知道我列举的哪些组是相机胶卷,看看代码【参考方案2】: imageArray = [[NSArray alloc] init];
NSMutableArray*mutableArray =[[NSMutableArray alloc]init];
NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init];
ALAssetsLibrary*library = [[ALAssetsLibrary alloc] init];
void (^enumerate)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
if ([[group valueForProperty:@"ALAssetsGroupPropertyType"] intValue] == ALAssetsGroupSavedPhotos)
NSLog(@"Camera roll");
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
ALAssetRepresentation *rep = [result defaultRepresentation];
NSLog(@"Asset Name ----> %@",rep.filename);
];
// I hot to check if group is Camera Roll ?
;
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:enumerate
failureBlock:nil];
【讨论】:
以上是关于ALAssetsLibrary 获取相机胶卷的主要内容,如果未能解决你的问题,请参考以下文章