update iOS code of getting medium info
This commit is contained in:
parent
9f8e0aefca
commit
d21edf5cac
@ -31,12 +31,12 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
|||||||
else if(call.method == "getMedium") {
|
else if(call.method == "getMedium") {
|
||||||
let arguments = call.arguments as! Dictionary<String, AnyObject>
|
let arguments = call.arguments as! Dictionary<String, AnyObject>
|
||||||
let mediumId = arguments["mediumId"] as! String
|
let mediumId = arguments["mediumId"] as! String
|
||||||
getMedium(
|
do {
|
||||||
mediumId: mediumId,
|
let medium = try getMedium(mediumId: mediumId)
|
||||||
completion: { (data: [String: Any?]?, error: Error?) -> Void in
|
result(medium)
|
||||||
result(data)
|
} catch {
|
||||||
|
result(nil)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
else if(call.method == "getThumbnail") {
|
else if(call.method == "getThumbnail") {
|
||||||
let arguments = call.arguments as! Dictionary<String, AnyObject>
|
let arguments = call.arguments as! Dictionary<String, AnyObject>
|
||||||
@ -217,7 +217,7 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getMedium(mediumId: String, completion: @escaping ([String : Any?]?, Error?) -> Void) {
|
private func getMedium(mediumId: String) throws -> [String: Any?] {
|
||||||
let fetchOptions = PHFetchOptions()
|
let fetchOptions = PHFetchOptions()
|
||||||
if #available(iOS 9, *) {
|
if #available(iOS 9, *) {
|
||||||
fetchOptions.fetchLimit = 1
|
fetchOptions.fetchLimit = 1
|
||||||
@ -225,10 +225,10 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
|||||||
let assets: PHFetchResult = PHAsset.fetchAssets(withLocalIdentifiers: [mediumId], options: fetchOptions)
|
let assets: PHFetchResult = PHAsset.fetchAssets(withLocalIdentifiers: [mediumId], options: fetchOptions)
|
||||||
|
|
||||||
if (assets.count <= 0) {
|
if (assets.count <= 0) {
|
||||||
completion(nil, NSError(domain: "photo_gallery", code: 404, userInfo: nil))
|
throw NSError(domain: "photo_gallery", code: 404)
|
||||||
} else {
|
} else {
|
||||||
let asset: PHAsset = assets[0]
|
let asset: PHAsset = assets[0]
|
||||||
completion(getMediumFromAsset(asset: asset), nil)
|
return getMediumFromAsset(asset: asset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user