Merge pull request #13 from quanghd96/master

fix collection nil
This commit is contained in:
Wenqi Li 2021-01-09 18:09:36 +08:00 committed by GitHub
commit 86b23f976c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -161,7 +161,7 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
return PHAsset.fetchAssets(with: options).count return PHAsset.fetchAssets(with: options).count
} }
return PHAsset.fetchAssets(in: collection!, options: options).count return PHAsset.fetchAssets(in: collection ?? PHAssetCollection.init(), options: options).count
} }
private func listMedia(albumId: String, skip: NSNumber?, take: NSNumber?, mediumType: String) -> NSDictionary { private func listMedia(albumId: String, skip: NSNumber?, take: NSNumber?, mediumType: String) -> NSDictionary {
@ -175,7 +175,7 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
let fetchResult = albumId == "__ALL__" let fetchResult = albumId == "__ALL__"
? PHAsset.fetchAssets(with: fetchOptions) ? PHAsset.fetchAssets(with: fetchOptions)
: PHAsset.fetchAssets(in: collection!, options: fetchOptions) : PHAsset.fetchAssets(in: collection ?? PHAssetCollection.init(), options: fetchOptions)
let start = skip?.intValue ?? 0 let start = skip?.intValue ?? 0
let total = fetchResult.count let total = fetchResult.count
let end = take == nil ? total : min(start + take!.intValue, total) let end = take == nil ? total : min(start + take!.intValue, total)