ALAssetsLibrary get Camera Roll

风格不统一 提交于 2019-12-14 03:40:05

问题


I enumerate all assets groups using ALAssetsLibrary

Here is code:

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

How to check if some current enumerated is CameraRoll?

Edit: As i tested it was always the last, using this enumerating. But i am not sure if it is the rule, are there any references that i missed?


回答1:


To get photos from camera roll use ALAssetsGroupSavedPhotos while enumerating assets library:

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

To detect what group you currently get:

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


来源:https://stackoverflow.com/questions/15570113/alassetslibrary-get-camera-roll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!