Swift:如何撷取除萤幕撷取画面,连拍,现场以外的所有相片(PHAsset)?

时间:2019-07-19 08:56:30

标签: nspredicate phasset photosframework phassetcollection phfetchoptions

我想从照片库中获取所有照片(PHAsset),除了屏幕截图,连拍,实时照片。

我尝试了以下代码,但返回了屏幕截图,连拍,实时照片

            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)

1 个答案:

答案 0 :(得分:0)

快速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)
}