ALAssetsLibrary获取相机胶卷

时间:2013-03-22 12:17:11

标签: ios objective-c alassetslibrary

我使用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

编辑:正如我测试的那样,它始终是最后一个,使用此枚举。但我不确定这是否是规则,是否有任何我错过的参考?

2 个答案:

答案 0 :(得分:14)

要在枚举资产库时使用ALAssetsGroupSavedPhotos从相机胶卷获取照片:

[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
                       usingBlock:enumerate
                     failureBlock:nil];

要检测您当前获得的群组:

if ([[group valueForProperty:@"ALAssetsGroupPropertyType"] intValue] == ALAssetsGroupSavedPhotos)
{
    NSLog(@"Camera roll");
}

答案 1 :(得分:3)

    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];