OGeek|极客世界-中国程序员成长平台

标题: ios - 使用 'hidden = YES' 谓词崩溃获取 PHAsset [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 07:57
标题: ios - 使用 'hidden = YES' 谓词崩溃获取 PHAsset

documentation 中所列, PHAsset 支持 hidden (or isHidden) fetch key。但是,当我尝试获取隐藏 Assets 时,我的应用程序因以下日志而崩溃:

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

这里是示例代码:

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

PHFetchResult *fetchResult = [PHAsset fetchAssetsWithOptionsptions];

return fetchResult;



Best Answer-推荐答案


我在第一个答案中没有仔细阅读问题,也许这会有所帮助

如果您只想要隐藏的专辑,为什么不使用? 子类型HAssetCollectionSubtypeSmartAlbumAllHidden

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

PHFetchResult *albums = [PHAssetCollection fetchAssetCollectionsWithTypeHAssetCollectionTypeSmartAlbum subtypeHAssetCollectionSubtypeSmartAlbumAllHidden options:nil];

关于ios - 使用 'hidden = YES' 谓词崩溃获取 PHAsset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30735939/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4