I am trying to fetch Photos from Photo library and I want to show only images from the Photo Library. I do not want to show videos.
I am using PHFetchOptions to fetch PHAssets from Photos library. Also I have provided a predicate to fetch only the photos. Below is my code:
let allPhotosOptions = PHFetchOptions()
allPhotosOptions.predicate = NSPredicate(format: "mediaType == 1")
allPhotosOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]
fetchResult = PHAsset.fetchAssets(with: allPhotosOptions)
However I am getting screenshots as well. I do not want to fetch the screenshots. I found that there is a property for that as well. It is called PHAssetMediaSubtype.photoScreenshot
I updated the predicate not to fetch screenshots but it doesn’t seem to work. So many of my other images are also being filtered which are not screenshots. below is my updated code for predicate
allPhotosOptions.predicate = NSPredicate(format: "mediaType == 1 AND mediaSubtypes != %d", PHAssetMediaSubtype.photoScreenshot.rawValue)
Source: Ios Questions
Your email address will not be published. Required fields are marked *
Save my name, email, and website in this browser for the next time I comment.
Our dedicated development team is here for you!
We can help you find answers to your question for as low as 5$.