1

I want to fetch all photos (PHAsset) except Screenshots, Burst, Live photos from Photo library.

I tried with code below but it returns Screenshots, Burst, Live photos

            let options = PHFetchOptions()
            options.sortDescriptors = [ NSSortDescriptor(key: "creationDate", ascending: true) ]
            options.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.image.rawValue)
            let assets = PHAsset.fetchAssets(with: options)
kuwhkud
  • 29
  • 1
  • 5

1 Answers1

1

Swift 5

private func fetchAllExceptLiveBurstScreenshots() -> PHFetchResult<PHAsset> {
        let options = PHFetchOptions()
        options.sortDescriptors = [ NSSortDescriptor(key: "creationDate", ascending: true) ]
        options.predicate = NSPredicate(
            format: "NOT (((mediaSubtype & %d) != 0) || ((mediaSubtype & %d) != 0) || (burstIdentifier != nil))",
            PHAssetMediaSubtype.photoLive.rawValue,
            PHAssetMediaSubtype.photoScreenshot.rawValue
        )
        return PHAsset.fetchAssets(with: .image, options: options)
}
V.V.V
  • 235
  • 1
  • 13