我可以通过这样做获取特定日期范围内的照片,但是如何进一步按其favorite
状态进行过滤?
PHFetchOptions *fetchOptions = [PHFetchOptions new];
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"(creationDate >= %@) && (creationDate <= %@)",startDateMinus24Hours,endDatePlus24Hours];
_assetsFetchResults = [PHAsset fetchAssetsWithOptions:fetchOptions];
我在谷歌上搜索了"PHFetchOptions谓词收藏夹",但找不到答案。如果您知道确切的答案,或者对谓词语法的引用,请告诉我。谢谢!
我想通了。
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];