1

我想从照片库中获取除屏幕截图、连拍、实时照片之外的所有照片(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)
4

1 回答 1

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)
}
于 2019-11-12T13:52:59.237 回答