2016-11-22 70 views
1

我使用的后续代码来获取所有的智能相册:的iOS PhotoKit:抓取所有的智能相册,除了全景

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

我怎样才能排除这种取全景智能相册?我假设我必须使用选项参数添加谓词,但我不知道如何格式化谓词。

+0

只要做提取然后消除或忽略Panoramas专辑不是更容易吗? – matt

回答

0

如果要排除全景图,请考虑使用数组并仅提取所需的集合。换句话说,将收藏列入白名单。或者您可以枚举集合并排除全景图。白名单也可以控制收藏的顺序。

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 
}