我正在尝试使用 the reference from here 获取设备中可用的相册列表:
到目前为止,我的 viewDidLoad 中有这个:
// Get albums
NSMutableArray *groups = [NSMutableArray new];
ALAssetsLibrary *library = [ALAssetsLibrary new];
ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) {
if (group) {
[groups addObject:group];
}
};
NSUInteger groupTypes = ALAssetsGroupAlbum;
[library enumerateGroupsWithTypes:groupTypes usingBlock:listGroupBlock failureBlock:nil];
NSLog(@"%@", groups);
但是,组数组中没有添加任何内容。我期待从 NSLog 中看到 2 个项目。
最佳答案
从 IOS9 开始,ALAsset 库已被弃用。相反,Photos Framework 引入了一种名为 PHAsset 的新 Assets 类型。您可以使用 PHAssetCollection 类检索相册。
PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:nil];
PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAny options:nil];
PHAssetCollectionType 定义相册的类型。您可以迭代 fetchResults 以获取每个专辑。
[userAlbums enumerateObjectsUsingBlock:^(PHAssetCollection *collection, NSUInteger idx, BOOL *stop) {}];
照片框架中的相册由 PHAssetCollection 表示。
关于ios - 获取相册列表的简单示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21131175/