Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How find the album name for each image using the ALAssetsLibrary

I’m using the AlAssetLibrary class for retrieve informations about the images inside my iPad. As you can see actually i have found the pixel width of the asset. What i need to find now is the name of the album for each asset. So if all assets are in the “camera” album i need to find it for each asset. How can i proceed? Here there is my code. Please note the NSString assetAlbumName. It is returning to me an error.

[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
        if (group) {

            [group setAssetsFilter:[ALAssetsFilter allPhotos]]; //search for the photos
            [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop){
                if (asset){
                    NSNumber *width = [[[asset defaultRepresentation] metadata] objectForKey:@"PixelWidth"]; //find the key with "PixelWidth" name
                    NSString *widthString = [NSString stringWithFormat:@"%@", width]; //take the value of the key

                    NSString *assetAlbumName = [asset valueForProperty:ALAssetsGroupPropertyName]; //it return to me an ALErrorInvalidProperty
                }
            }
        }
}

Thanks

like image 519
Hieicker Avatar asked Feb 15 '23 20:02

Hieicker


1 Answers

you may try

 NSString *albumName = [group valueForProperty:ALAssetsGroupPropertyName];

you are doing

 NSString *albumName = [assets valueForProperty:ALAssetsGroupPropertyName];
like image 137
Rajpal Thakur Avatar answered May 16 '23 06:05

Rajpal Thakur