Swift iOS:-如何将.livePhotos排除在PHFetchOptions中?

时间:2018-09-12 01:42:01

标签: ios swift phasset phassetcollection phfetchoptions

在使用UIImagePicker时使用@matt的Alea: "i32 is not struct type,一旦使用以下图片选择了图像,我可以防止用户选择.livePhoto

let asset = info[UIImagePickerControllerPHAsset] as? PHAsset

if asset?.playbackStyle == .livePhoto { 
   // alert user this photo isn't a possibility 
}

使用PHFetchOptions时,如何阻止它们显示而不是在enumerateObjects回调中将其过滤掉?

fileprivate func fetchPhotos() {

    let fetchOptions = PHFetchOptions()
    fetchOptions.fetchLimit = 1000
    let sortDescriptor = NSSortDescriptor(key: "creationDate", ascending: false)
    fetchOptions.sortDescriptors = [sortDescriptor]

    let allPhotos = PHAsset.fetchAssets(with: .video, options: fetchOptions)

    allPhotos.enumerateObjects {
        [weak self] (asset, count, stop) in

        if asset.playbackStyle == .livePhoto {
            return
        }

        let imageManager = PHImageManager.default()
        let targetSize = CGSize(width: 350, height: 350)
        let options = PHImageRequestOptions()
        options.isSynchronous = true

        imageManager.requestImage(for: asset, targetSize: targetSize, contentMode: .aspectFit, options: options, resultHandler: {
            [weak self] (image, info) in

            if let image = image {
                self?.tableData.append(image)
            }

            if count == allPhotos.count - 1 {
                self?.collectionView.reloadData()
            }
        })
    }
}

1 个答案:

答案 0 :(得分:1)

您可以使用predicate的{​​{1}}属性。如果资产的PHFetchOptions属性表明它是实时照片,则将谓词设置为失败。

mediaSubtype