Merge remote-tracking branch 'Ashhad08/master'

This commit is contained in:
Wenqi Li 2024-03-24 16:50:26 +08:00
commit 0ec4144c5f

View File

@ -326,13 +326,18 @@ public class PhotoGalleryPlugin: NSObject, FlutterPlugin {
fetchOptions.fetchLimit = 1 fetchOptions.fetchLimit = 1
} }
let assets: PHFetchResult<PHAsset> var assets: PHFetchResult<PHAsset>
if(albumId == "__ALL__") {
if albumId == "__ALL__" {
assets = PHAsset.fetchAssets(with: fetchOptions) assets = PHAsset.fetchAssets(with: fetchOptions)
} else if let collection = self.assetCollections.first(where: { $0.localIdentifier == albumId }) {
assets = PHAsset.fetchAssets(in: collection, options: fetchOptions)
} else { } else {
assets = PHAsset.fetchAssets(in: self.assetCollections.first(where: { (collection) -> Bool in // Handle the case where the collection is nil
collection.localIdentifier == albumId print("Error: Collection with ID \(albumId) not found")
})!, options: fetchOptions) // You might want to provide a default value or handle this case according to your app's logic
// For now, let's just assign an empty fetch result
assets = PHAsset.fetchAssets(with: fetchOptions)
} }
if (assets.count > 0) { if (assets.count > 0) {