From cbe3150ef037e238553c6bf8f2053eaf53080613 Mon Sep 17 00:00:00 2001 From: Kwanwoo Kim Date: Sun, 25 Jun 2023 22:41:36 -0700 Subject: [PATCH] LightWeight option for iOS --- ios/Classes/SwiftPhotoGalleryPlugin.swift | 24 ++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/ios/Classes/SwiftPhotoGalleryPlugin.swift b/ios/Classes/SwiftPhotoGalleryPlugin.swift index 2bd4b5f..54733b4 100644 --- a/ios/Classes/SwiftPhotoGalleryPlugin.swift +++ b/ios/Classes/SwiftPhotoGalleryPlugin.swift @@ -25,7 +25,8 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin { let newest = arguments["newest"] as! Bool let skip = arguments["skip"] as? NSNumber let take = arguments["take"] as? NSNumber - result(listMedia(albumId: albumId, mediumType: mediumType, newest: newest, skip: skip, take: take)) + let lightWeight = arguments["lightWeight"] as? Bool + result(listMedia(albumId: albumId, mediumType: mediumType, newest: newest, skip: skip, take: take, lightWeight: lightWeight)) } else if(call.method == "getMedium") { let arguments = call.arguments as! Dictionary @@ -182,7 +183,7 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin { return PHAsset.fetchAssets(in: collection ?? PHAssetCollection.init(), options: options).count } - private func listMedia(albumId: String, mediumType: String?, newest: Bool, skip: NSNumber?, take: NSNumber?) -> NSDictionary { + private func listMedia(albumId: String, mediumType: String?, newest: Bool, skip: NSNumber?, take: NSNumber?, lightWeight: Bool? = false) -> NSDictionary { let fetchOptions = PHFetchOptions() fetchOptions.predicate = predicateFromMediumType(mediumType: mediumType) fetchOptions.sortDescriptors = [ @@ -203,7 +204,11 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin { var items = [[String: Any?]]() for index in start.. [String: Any?] { + return [ + "id": asset.localIdentifier, + "mediumType": toDartMediumType(value: asset.mediaType), + "height": asset.pixelHeight, + "width": asset.pixelWidth, + "duration": NSInteger(asset.duration * 1000), + "creationDate": (asset.creationDate != nil) ? NSInteger(asset.creationDate!.timeIntervalSince1970 * 1000) : nil, + "modifiedDate": (asset.modificationDate != nil) ? NSInteger(asset.modificationDate!.timeIntervalSince1970 * 1000) : nil + ] + } private func getMediumFromAssetAsync(asset: PHAsset, completion: @escaping ([String : Any?]?, Error?) -> Void) -> Void { let mimeType = self.extractMimeTypeFromAsset(asset: asset)