【问题标题】:NSPredicate to not include Loop and Bounce Live PhotosNSPredicate 不包括 Loop 和 Bounce Live Photos
【发布时间】:2023-03-23 01:43:01
【问题描述】:

在我的应用中,我只显示用户可以编辑的资产,所以我只显示照片 - 没有视频。 iOS 11 中的新功能 Live Photos 有两种效果可以有效地将照片变成视频 - 循环和反弹。这些实况照片无法在照片应用程序中编辑 - 插件按钮被禁用。我需要在我的PHFetchResult 中过滤掉那些。但是mediaTypeimage 仍然包括这些“直播视频”。如何从获取中排除那些?也许与PHAssetplaybackStyle 有关?

let photoLibraryFetchResult = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .smartAlbumUserLibrary, options: nil)  
let assetCollection = photoLibraryFetchResult.firstObject!  

let imagesOnlyFetchOptions = PHFetchOptions()  
imagesOnlyFetchOptions.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.image.rawValue)  

let assetsFetchResults = PHAsset.fetchAssets(in: assetCollection, options: imagesOnlyFetchOptions)

【问题讨论】:

    标签: ios swift phasset photosframework phfetchoptions


    【解决方案1】:

    尝试查看playbackStyle 值。 (Read more here)

    枚举有以下选项:

    case image
    case imageAnimated
    case livePhoto
    case unsupported
    case video
    case videoLooping
    

    【讨论】:

    • 酷,语法是:NSPredicate(format: "playbackStyle = %d or playbackStyle = %d", PHAsset.PlaybackStyle.image.rawValue, PHAsset.PlaybackStyle.livePhoto.rawValue)
    猜你喜欢
    • 1970-01-01
    • 2020-08-29
    • 2014-05-14
    • 2016-04-08
    • 1970-01-01
    • 2017-06-01
    • 1970-01-01
    • 2014-07-24
    • 1970-01-01
    相关资源
    最近更新 更多