我正在使用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
}
}
}
}
由于
答案 0 :(得分:4)
你可以尝试
NSString *albumName = [group valueForProperty:ALAssetsGroupPropertyName];
你正在做什么
NSString *albumName = [assets valueForProperty:ALAssetsGroupPropertyName];
答案 1 :(得分: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];
这是apple的示例代码,将为您提供更多帮助..