0

I can fetch photos in a certain date range by doing this, but how can I further filter by their favorite statuses?

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

I googled for "PHFetchOptions predicate favorites", but couldn't find an answer. If you know the exact answer, or a reference to predicate syntax, please let me know. Thanks!

kalpesh satasiya
  • 799
  • 8
  • 18
tsuyoski
  • 614
  • 5
  • 22

1 Answers1

1

I figured it out.

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];
tsuyoski
  • 614
  • 5
  • 22