获取每张专辑的所有相册和缩略图列表

nic*_*ick 10 iphone ios ios5

如何获取iOS中所有相册的列表?我知道图像选择器必须在某处有一个列表,因为它将它们全部显示给用户.一旦我有了相册,我将如何显示特定相册中所有图像的缩略图?我似乎无法在文档中找到任何内容,但我确信必须有一种方法可以做到这一点.

Fil*_*lic 20

UIImagePickerController如果这就是你要问的那样,你就无法得到那种信息.

看看AssetsLibrary框架.甚至还有示例代码实现了自定义图像选择器.


lbs*_*eek 19

枚举并获取最新图像及其缩略图.

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");
}];
Run Code Online (Sandbox Code Playgroud)