PHFetchOptions mediaSubtype predicate

The following predicate should only retrieve all screenshots that work very well.

options.predicate = [NSPredicate predicateWithFormat:@"(mediaSubtype & %d) != 0", PHAssetMediaSubtypePhotoScreenshot]; 

However, if I try to exclude screenshots only using the follwing predicate, all images are excluded

 options.predicate = [NSPredicate predicateWithFormat:@"(mediaSubtype & %d) = 0", PHAssetMediaSubtypePhotoScreenshot]; 

All the attempts that I am trying to make are to exclude fingerprints from the resource extraction screen.

Is this a known bug or am I missing something?

+5
source share
2 answers

I did a quick check and this seems to work for me:

  PHFetchOptions *options = [[PHFetchOptions alloc] init]; options.predicate = [NSPredicate predicateWithFormat:@"(mediaSubtype & %d) == 0", PHAssetMediaSubtypePhotoScreenshot]; 

Note the double equal in the predicate for comparison instead of the only one.

+3
source

After a few hours, I found a workaround using the NOT operator:

 NSPredicate(format: "NOT ((mediaSubtype & %d) != 0)", PHAssetMediaSubtype.PhotoScreenshot.rawValue) 
+1
source

Source: https://habr.com/ru/post/1242387/


All Articles