繁体   English   中英

iOS PhotoKit:获取除全景照片以外的所有智能相册

[英]iOS PhotoKit: Fetch all smart albums except panoramas

我使用以下代码来获取所有智能相册:

PHAssetCollection.fetchAssetCollections(with: PHAssetCollectionType.smartAlbum, subtype: PHAssetCollectionSubtype.albumRegular, options: nil)

如何从此抓取中排除Panoramas智能相册? 我假设我必须使用options param添加谓词,但我不知道如何格式化谓词。

如果要排除全景图,请考虑使用数组并仅获取所需的集合。 换句话说,白名单集合。 或者您可以枚举整个集合并排除全景图。 白名单还可以控制集合的顺序。

var smartAlbums: [PHAssetCollection] = []
let subtypes:[PHAssetCollectionSubtype] = [
    // all photos collection
    // .smartAlbumUserLibrary,
   .smartAlbumFavorites,
   .smartAlbumPanoramas,
   .smartAlbumLivePhotos,
   .smartAlbumBursts,
   .smartAlbumDepthEffect,
   .smartAlbumLongExposures,
   .smartAlbumScreenshots,
   .smartAlbumSelfPortraits
]

smartAlbums = fetchSmartCollections(with: .smartAlbum, subtypes: subtypes)

private func fetchSmartCollections(with: PHAssetCollectionType, subtypes: [PHAssetCollectionSubtype]) -> [PHAssetCollection] {
    var collections:[PHAssetCollection] = []
    let options = PHFetchOptions()
    options.includeHiddenAssets = false

    for subtype in subtypes {
        if let collection = PHAssetCollection.fetchAssetCollections(with: with, subtype: subtype, options: options).firstObject {
            collections.append(collection)
        }
    }

    return collections
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM