0

我只是想将位于名为“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"];

但它不起作用。有人可以帮我吗?

4

1 回答 1

2

哇。经过大约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

    }];
于 2015-10-18T04:40:51.573 回答