【问题标题】:Swift: how to fetch all photos (PHAsset) except Screenshots, Burst, Live?Swift:如何获取除 Screenshots、Burst、Live 之外的所有照片(PHAsset)?
【发布时间】:2019-11-28 05:45:15
【问题描述】:

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

【问题讨论】:

    标签: nspredicate phasset photosframework phassetcollection phfetchoptions


    【解决方案1】:

    斯威夫特 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)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-25
      相关资源
      最近更新 更多