我想从照片库中获取所有照片(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)
答案 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)
}