PHFetchResult for Custom Album Only

1.5k Views Asked by At

I'm simply trying to access the photos located in a custom folder called "MyFolder" to my UICollectionView. I can easily get this working with "all photos and videos" with the following code, but I can not figure out how to filter the results to only include my folder name:

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
}];

I have tried using this:

allPhotosOptions.predicate = [NSPredicate predicateWithFormat:@"title = %@", @"Coached"];

But it does not work. Can someone please help me with this?

1

There are 1 best solutions below

0
On

Wow. After about 5+ hours of suffering. It was quite simple. Here is the code that works:

__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

    }];