|
@@ -197,12 +197,6 @@ extension NXLPhotoLibrary {
|
|
|
let durationPredicate = NSPredicate(format: "duration < %f", maxVideoDuration)
|
|
|
options.merge(predicate: durationPredicate)
|
|
|
}
|
|
|
-
|
|
|
- /// 最小时长
|
|
|
- if let minVideoDuration = configure.minVideoDuration {
|
|
|
- let durationPredicate = NSPredicate(format: "duration >= %f", minVideoDuration)
|
|
|
- options.merge(predicate: durationPredicate)
|
|
|
- }
|
|
|
return options
|
|
|
}
|
|
|
|
|
@@ -217,4 +211,132 @@ extension NXLPhotoLibrary {
|
|
|
return PHAsset.fetchAssets(in: phAssetCollection, options: options)
|
|
|
}
|
|
|
|
|
|
+ /// 提取结果
|
|
|
+ /// - Parameter configure: NXLPhotoPickerConfigure
|
|
|
+ func fetchCollection(configure: NXLPhotoPickerConfigure) {
|
|
|
+ let isUsedCamera = configure.isUsedCamera
|
|
|
+ let options = getOption(configure: configure)
|
|
|
+ let fetchCollectionOption = configure.fetchCollectionOption
|
|
|
+
|
|
|
+
|
|
|
+ /// 获取相册
|
|
|
+ /// - Parameters:
|
|
|
+ /// - subType: 类型
|
|
|
+ /// - result: 返回值
|
|
|
+ func getAlbum(subType: PHAssetCollectionSubtype, result: inout [NXLAssetsCollection]) {
|
|
|
+ let collectionOption = fetchCollectionOption[.assetCollections(.album)]
|
|
|
+ let fetchCollection = PHAssetCollection.fetchAssetCollections(with: .album,
|
|
|
+ subtype: subType,
|
|
|
+ options: collectionOption)
|
|
|
+ var collections = [PHAssetCollection]()
|
|
|
+ fetchCollection.enumerateObjects { (collection, index, _) in
|
|
|
+ if configure.isAllowedAlbumCloudShared == false && collection.assetCollectionSubtype == .albumCloudShared {
|
|
|
+ }else {
|
|
|
+ collections.append(collection)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for collection in collections {
|
|
|
+ if !result.contains(where: { $0.localIdentifier == collection.localIdentifier }) {
|
|
|
+ var assetsCollection = NXLAssetsCollection(collection: collection)
|
|
|
+ assetsCollection.title = configure.customLocalizedTitle[assetsCollection.title] ?? assetsCollection.title
|
|
|
+ assetsCollection.fetchResult = PHAsset.fetchAssets(in: collection, options: options)
|
|
|
+ if assetsCollection.count > 0 {
|
|
|
+ result.append(assetsCollection)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 获取小相册
|
|
|
+ /// - Parameters:
|
|
|
+ /// - subType: 类型
|
|
|
+ /// - isUseCamera: 是否使用相机
|
|
|
+ /// - result: [NXLAssetsCollection]
|
|
|
+ @discardableResult
|
|
|
+
|
|
|
+ func getSmartAlbum(subType: PHAssetCollectionSubtype, isUseCamera: Bool? = false, result: inout [NXLAssetsCollection])
|
|
|
+ -> NXLAssetsCollection?
|
|
|
+ {
|
|
|
+ let collectionOption = fetchCollectionOption[.assetCollections(.smartAlbum)]
|
|
|
+ let fetchCollection = PHAssetCollection.fetchAssetCollections(with: .smartAlbum,
|
|
|
+ subtype: subType,
|
|
|
+ options: collectionOption)
|
|
|
+ if
|
|
|
+ let collection = fetchCollection.firstObject,
|
|
|
+ result.contains(where: { $0.localIdentifier == collection.localIdentifier }) == false
|
|
|
+ {
|
|
|
+ var assetsCollection = NXLAssetsCollection(collection: collection)
|
|
|
+ assetsCollection.title = configure.customLocalizedTitle[assetsCollection.title] ?? assetsCollection.title
|
|
|
+ assetsCollection.fetchResult = PHAsset.fetchAssets(in: collection, options: options)
|
|
|
+ if assetsCollection.count > 0 || isUseCamera ?? false {
|
|
|
+ result.append(assetsCollection)
|
|
|
+ return assetsCollection
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ if let fetchCollectionTypes = configure.fetchCollectionTypes {
|
|
|
+ DispatchQueue.global(qos: .userInteractive).async { [weak self] in
|
|
|
+ var assetCollections = [NXLAssetsCollection]()
|
|
|
+ for (type,subType) in fetchCollectionTypes {
|
|
|
+ if type == .smartAlbum {
|
|
|
+ getSmartAlbum(subType: subType, result: &assetCollections)
|
|
|
+ }else {
|
|
|
+ getAlbum(subType: subType, result: &assetCollections)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ self?.delegate?.loadCompleteAllCollection(collections: assetCollections)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ DispatchQueue.global(qos: .userInteractive).async { [weak self] in
|
|
|
+ var assetCollections = [NXLAssetsCollection]()
|
|
|
+ //Camera Roll
|
|
|
+ let camerarollCollection = getSmartAlbum(subType: .smartAlbumUserLibrary,
|
|
|
+ isUseCamera: isUsedCamera,
|
|
|
+ result: &assetCollections)
|
|
|
+ if var cameraRoll = camerarollCollection {
|
|
|
+ cameraRoll.title = configure.customLocalizedTitle[cameraRoll.title] ?? cameraRoll.title
|
|
|
+ cameraRoll.isUsedCamera = isUsedCamera
|
|
|
+ assetCollections[0] = cameraRoll
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ self?.delegate?.loadCameraRollCollection(collection: cameraRoll)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //Selfies
|
|
|
+ getSmartAlbum(subType: .smartAlbumSelfPortraits, result: &assetCollections)
|
|
|
+ //Panoramas
|
|
|
+ getSmartAlbum(subType: .smartAlbumPanoramas, result: &assetCollections)
|
|
|
+ //Favorites
|
|
|
+ getSmartAlbum(subType: .smartAlbumFavorites, result: &assetCollections)
|
|
|
+ //CloudShared
|
|
|
+ getSmartAlbum(subType: .albumCloudShared, result: &assetCollections)
|
|
|
+ //get all another albums
|
|
|
+ getAlbum(subType: .any, result: &assetCollections)
|
|
|
+ if configure.isAllowedVideo ?? false {
|
|
|
+ //Videos
|
|
|
+ getSmartAlbum(subType: .smartAlbumVideos, result: &assetCollections)
|
|
|
+ }
|
|
|
+ //Album
|
|
|
+ let collectionOption = fetchCollectionOption[.topLevelUserCollections]
|
|
|
+ let albumsResult = PHCollectionList.fetchTopLevelUserCollections(with: collectionOption)
|
|
|
+ albumsResult.enumerateObjects({ (collection, index, stop) -> Void in
|
|
|
+ guard let collection = collection as? PHAssetCollection else { return }
|
|
|
+ var assetsCollection = NXLAssetsCollection(collection: collection)
|
|
|
+ assetsCollection.title = configure.customLocalizedTitle[assetsCollection.title] ?? assetsCollection.title
|
|
|
+ assetsCollection.fetchResult = PHAsset.fetchAssets(in: collection, options: options)
|
|
|
+ if assetsCollection.count > 0, !assetCollections.contains(where: { $0.localIdentifier == collection.localIdentifier }) {
|
|
|
+ assetCollections.append(assetsCollection)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ self?.delegate?.loadCompleteAllCollection(collections: assetCollections)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|