我可以通过这样做来获取某个日期范围内的照片,但是如何进一步根据它们的favorite状态进行过滤呢?
PHFetchOptions *fetchOptions = [PHFetchOptions new];
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"(creationDate >= %@) && (creationDate <= %@)",startDateMinus24Hours,endDatePlus24Hours];
_assetsFetchResults = [PHAsset fetchAssetsWithOptions:fetchOptions];我在谷歌上搜索了"PHFetchOptions predicate favorites",但是没有找到答案。如果您知道确切的答案,或者对谓词语法的引用,请让我知道。谢谢!
发布于 2018-01-21 07:04:40
我想通了。
PHFetchOptions *fetchOptions = [PHFetchOptions new];
NSString *format = @"(creationDate >= %@) && (creationDate <= %@)";
if (showFavoritePhotosOnly) {
format = [format stringByAppendingString:@" && (favorite == true)"];
}
fetchOptions.predicate = [NSPredicate predicateWithFormat:format,startDateMinus24Hours,endDatePlus24Hours]; //iwashere
_assetsFetchResults = [PHAsset fetchAssetsWithOptions:fetchOptions];https://stackoverflow.com/questions/48236755
复制相似问题