PHFetchResult только для пользовательского альбома
Я просто пытаюсь получить доступ к фотографиям, расположенным в пользовательской папке с именем "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"];
Но это не работает. Может кто-нибудь помочь мне с этим?
1 ответ
Вот это да. Примерно через 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
}];