nick
nick

Reputation: 2853

Get list of all photo albums and thumbnails for each album

How do I get a list of all the photo albums in iOS? I know the image picker has to have a list of them somewhere since it displays them all to the user. Once I have the photo albums, how would I go about displaying thumbnails of all the images in a particular album? I can't seem to find anything in the docs, but I'm sure there's got to be a way to do it.

Upvotes: 10

Views: 28809

Answers (3)

Stephen H King
Stephen H King

Reputation: 266

The Assets Library framework is deprecated as of iOS 9.0. Instead, use the Photos framework, which in iOS 8.0 and later provides more features and better performance for working with a user’s photo library.

Check Photos framework, and inspect: PHAsset, PHAssetCollection, and PHCollectionList, depending on your needs.

Upvotes: 0

andrewchan2022
andrewchan2022

Reputation: 5310

Enumerate and get latest image and its thumbnail.

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {

    // Within the group enumeration block, filter to enumerate just photos.
    [group setAssetsFilter:[ALAssetsFilter allPhotos]];

    // Chooses the photo at the last index
    [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
        // The end of the enumeration is signaled by asset == nil.
        if (alAsset) {
            ALAssetRepresentation *representation = [alAsset defaultRepresentation];
            UIImage *latestPhoto = [UIImage imageWithCGImage:[representation fullScreenImage]];


            UIImage *latestPhotoThumbnail =  [UIImage imageWithCGImage:[alAsset thumbnail]];


            // Stop the enumerations
            *stop = YES; *innerStop = YES;

            // Do something interesting with the AV asset.
            //[self sendTweet:latestPhoto];
        }
    }];
} failureBlock: ^(NSError *error) {
    // Typically you should handle an error more gracefully than this.
    NSLog(@"No groups");
}];

Upvotes: 19

Filip Radelic
Filip Radelic

Reputation: 26683

You can't get that kind of information from UIImagePickerController if that is what you are asking.

Take a look at AssetsLibrary framework. There is even sample code that implements a custom image picker.

Upvotes: 20

Related Questions