如果要排除全景图,请考虑使用数组并仅提取所需的集合。换句话说,将收藏列入白名单。或者您可以枚举集合并排除全景图。白名单也可以控制收藏的顺序。
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
}
只要做提取然后消除或忽略Panoramas专辑不是更容易吗? – matt