simplify deleting medium method in iOS code
This commit is contained in:
parent
185628470a
commit
7635a8243f
@ -237,30 +237,23 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func deleteMedium(mediumId: String, completion: @escaping (Bool, Error?) -> Void) {
|
private func deleteMedium(mediumId: String, completion: @escaping (Bool, Error?) -> Void) {
|
||||||
let fetchOptions = PHFetchOptions()
|
let fetchOptions = PHFetchOptions()
|
||||||
if #available(iOS 9, *) {
|
if #available(iOS 9, *) {
|
||||||
fetchOptions.fetchLimit = 1
|
fetchOptions.fetchLimit = 1
|
||||||
}
|
}
|
||||||
let assets: PHFetchResult = PHAsset.fetchAssets(withLocalIdentifiers: [mediumId], options: fetchOptions)
|
let assets: PHFetchResult = PHAsset.fetchAssets(withLocalIdentifiers: [mediumId], options: fetchOptions)
|
||||||
|
|
||||||
if assets.count <= 0 {
|
|
||||||
completion(false, NSError(domain: "photo_gallery", code: 404, userInfo: nil))
|
|
||||||
} else {
|
|
||||||
let asset: PHAsset = assets[0]
|
|
||||||
deleteAssets(assets: [asset]) { success, error in
|
|
||||||
completion(success, error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func deleteAssets(assets: [PHAsset], completion: @escaping (Bool, Error?) -> Void) {
|
if assets.count <= 0 {
|
||||||
PHPhotoLibrary.shared().performChanges({
|
completion(false, NSError(domain: "photo_gallery", code: 404, userInfo: nil))
|
||||||
PHAssetChangeRequest.deleteAssets(assets as NSFastEnumeration)
|
} else {
|
||||||
}, completionHandler: completion)
|
let asset: PHAsset = assets[0]
|
||||||
}
|
PHPhotoLibrary.shared().performChanges({
|
||||||
|
PHAssetChangeRequest.deleteAssets([asset] as NSFastEnumeration)
|
||||||
|
}, completionHandler: completion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private func getThumbnail(
|
private func getThumbnail(
|
||||||
mediumId: String,
|
mediumId: String,
|
||||||
width: NSNumber?,
|
width: NSNumber?,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user