Question

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

Was it helpful?

Solution

you may try

 NSString *albumName = [group valueForProperty:ALAssetsGroupPropertyName];

you are doing

 NSString *albumName = [assets valueForProperty:ALAssetsGroupPropertyName];

OTHER TIPS

*// emumerate through our groups and only add groups that contain photos*
ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) {

    ALAssetsFilter *onlyPhotosFilter = [ALAssetsFilter allPhotos];
    [group setAssetsFilter:onlyPhotosFilter];
    if ([group numberOfAssets] > 0)
    {
        [self.groups addObject:group]; //groups is NSMutableArray
    }
    else
    {
        [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
    }
};

// enumerate only photos
NSUInteger groupTypes = ALAssetsGroupAlbum | ALAssetsGroupEvent | ALAssetsGroupFaces | ALAssetsGroupSavedPhotos;
[self.assetsLibrary enumerateGroupsWithTypes:groupTypes usingBlock:listGroupBlock failureBlock:failureBlock];


 ALAssetsGroup *groupAsset = groups[objectIndex];
NSString *albumName = [groupAsset valueForProperty:ALAssetsGroupPropertyName];

Here is apple's sample code, will help you more..

https://developer.apple.com/library/ios/samplecode/MyImagePicker/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010135

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top