如何使用 Objective C 的 PHFetchOptions 只获取最喜欢的图片
How do you fetch only favorite pictures using Objective C's PHFetchOptions
我可以通过这样做来获取特定日期范围内的照片,但是我怎样才能进一步过滤他们的 favorite
状态?
PHFetchOptions *fetchOptions = [PHFetchOptions new];
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"(creationDate >= %@) && (creationDate <= %@)",startDateMinus24Hours,endDatePlus24Hours];
_assetsFetchResults = [PHAsset fetchAssetsWithOptions:fetchOptions];
我用谷歌搜索了 "PHFetchOptions predicate favorites",但找不到答案。如果您知道确切的答案或谓词语法的参考,请告诉我。谢谢!
我想通了。
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];
我可以通过这样做来获取特定日期范围内的照片,但是我怎样才能进一步过滤他们的 favorite
状态?
PHFetchOptions *fetchOptions = [PHFetchOptions new];
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"(creationDate >= %@) && (creationDate <= %@)",startDateMinus24Hours,endDatePlus24Hours];
_assetsFetchResults = [PHAsset fetchAssetsWithOptions:fetchOptions];
我用谷歌搜索了 "PHFetchOptions predicate favorites",但找不到答案。如果您知道确切的答案或谓词语法的参考,请告诉我。谢谢!
我想通了。
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];