4

我正在使用 AlAssetLibrary 类来检索有关我 iPad 内图像的信息。正如您所看到的,实际上我已经找到了资产的像素宽度。我现在需要找到的是每个资产的专辑名称。因此,如果所有资产都在“相机”相册中,我需要为每个资产找到它。我该如何进行?这是我的代码。请注意 NSString assetAlbumName。它返回给我一个错误。

[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
                }
            }
        }
}

谢谢

4

2 回答 2

4

你可以试试

 NSString *albumName = [group valueForProperty:ALAssetsGroupPropertyName];

你在做

 NSString *albumName = [assets valueForProperty:ALAssetsGroupPropertyName];
于 2013-10-30T08:58:20.610 回答
4
*// 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];

这是苹果的示例代码,将为您提供更多帮助..

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

于 2013-10-30T09:15:09.567 回答