6

Following predicate should fetch all the screenshots only, which work just fine.

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

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

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

All Im trying to do is to exlude screeshots from asset fetch.

Is this known bug or am I missing something ?

stringCode
  • 2,274
  • 1
  • 23
  • 32
  • 1
    Possible duplicate: [NSPredicate to exclude slow motion videos from PHFetchResults](http://stackoverflow.com/questions/31939082/) (same general issue, just a different `PHAssetMediaSubtype` value). Try that fix? – rickster Feb 05 '16 at 19:12
  • Thank you for your comment, sadly even though the answer is marked as correct it does not actually work. – stringCode Feb 06 '16 at 09:26

2 Answers2

6

I made 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 to do the comparison instead of the single one.

  • Thank you for your reply. I tried it before an again now. This will strip screenshot but most of regular photos as well :-) The ones of subtype PHAssetMediaSubtypeNone specifically. – stringCode Feb 15 '16 at 15:22
  • 2
    That shouldn't happen but actually does. I have made some experiments and seems like the filtering is a little bit buggy. Using predicates to checking for a combination of the other subtypes also did not work and this is even the Apple recommended way in their documentation. Once that said I think the best way to deal with this at the moment is to get the full set and filter the array manually through enumeration although if you need live updates of the fetch you will be out of look in that case. – Pablo Carrillo Alvarez Feb 17 '16 at 16:05
  • Yeah at this point I came to the same conclusion, I was hoping I was doing something stupid but it seems its Apple's bug. Will fill the radar. Thank you for your help and time – stringCode Feb 17 '16 at 20:13
  • @PabloCarrilloAlvarez I used that code I faced same problem (with regular photo) but I guess I solved it or may be apple fixed there bug when I used `%ld` instead of `%d` . – Sk Borhan Uddin Mar 28 '17 at 12:22
6

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

NSPredicate(format: "NOT ((mediaSubtype & %d) != 0)", PHAssetMediaSubtype.PhotoScreenshot.rawValue)
topascz
  • 61
  • 1
  • 3