我只是想将位于名为“MyFolder”的自定义文件夹中的照片访问到我的 UICollectionView。我可以使用以下代码轻松地处理“所有照片和视频”,但我不知道如何过滤结果以仅包含我的文件夹名称:
PHFetchOptions *allPhotosOptions = [PHFetchOptions new];
allPhotosOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
PHFetchResult *videos = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeVideo options:allPhotosOptions];
[videos enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {
//add assets to array
}];
我试过用这个:
allPhotosOptions.predicate = [NSPredicate predicateWithFormat:@"title = %@", @"Coached"];
但它不起作用。有人可以帮我吗?
最佳答案
哇。经过大约 5 个多小时的痛苦。这很简单。这是有效的代码:
__block PHAssetCollection *collection;
// Find the album
PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"title = %@", @"YOUR_CUSTOM_ALBUM_NAME"];
collection = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum
subtype:PHAssetCollectionSubtypeAny
options:fetchOptions].firstObject;
PHFetchResult *collectionResult = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
[collectionResult enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {
//add assets to an array for later use in the uicollectionviewcell
}];
关于ios - 仅自定义相册的 PHFetchResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33194329/