ALAssetsLibrary获取相机胶卷

7
我使用 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个回答

14

在枚举资产库时,使用ALAssetsGroupSavedPhotos来从相机卷中获取照片:

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

为了检测当前所属的用户组,请执行以下操作:
if ([[group valueForProperty:@"ALAssetsGroupPropertyType"] intValue] == ALAssetsGroupSavedPhotos)
{
    NSLog(@"Camera roll");
}

我看到了这个解决方案,但我需要知道我的枚举组中哪一个是相机胶卷,请查看代码。 - B.S.

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接