0

我可以通过这样做来获取特定日期范围内的照片,但我如何进一步过滤它们的favorite状态?

PHFetchOptions *fetchOptions = [PHFetchOptions new];
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"(creationDate >= %@) && (creationDate <= %@)",startDateMinus24Hours,endDatePlus24Hours];
_assetsFetchResults = [PHAsset fetchAssetsWithOptions:fetchOptions];

我搜索了“PHFetchOptions 谓词收藏夹”,但找不到答案。如果您知道确切的答案或对谓词语法的引用,请告诉我。谢谢!

4

1 回答 1

1

我想到了。

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];
于 2018-01-20T23:04:39.897 回答