Fetch PHAsset with 'hidden = YES' predicate crash

1k views Asked by At

As listed in documentation, PHAsset supports hidden (or isHidden) fetch key. But when I'm trying to fetch hidden assets my app crashing with following log:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unsupported predicate in fetch options: hidden == 1'

Here is sample code:

PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.wantsIncrementalChangeDetails = YES;
options.includeAllBurstAssets = YES;
options.includeHiddenAssets = YES;
options.predicate = [NSPredicate predicateWithFormat:@"hidden = YES"];

PHFetchResult *fetchResult = [PHAsset fetchAssetsWithOptions:options];

return fetchResult;
1

There are 1 answers

2
Ryan Heitner On

I did not read the question carefully in my first answer, perhaps this will help

If you only want the Hidden Albums why not use ? subtype:PHAssetCollectionSubtypeSmartAlbumAllHidden

PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.wantsIncrementalChangeDetails = YES;
options.includeAllBurstAssets = YES;
options.includeHiddenAssets = YES;
options.predicate = [NSPredicate predicateWithFormat:@"mediaType == %d",PHAssetMediaTypeImage];

PHFetchResult *albums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeSmartAlbumAllHidden options:nil];