simplify deleting medium method in iOS code
This commit is contained in:
parent
185628470a
commit
7635a8243f
@ -237,29 +237,22 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private func deleteMedium(mediumId: String, completion: @escaping (Bool, Error?) -> Void) {
|
||||
let fetchOptions = PHFetchOptions()
|
||||
if #available(iOS 9, *) {
|
||||
fetchOptions.fetchLimit = 1
|
||||
private func deleteMedium(mediumId: String, completion: @escaping (Bool, Error?) -> Void) {
|
||||
let fetchOptions = PHFetchOptions()
|
||||
if #available(iOS 9, *) {
|
||||
fetchOptions.fetchLimit = 1
|
||||
}
|
||||
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]
|
||||
PHPhotoLibrary.shared().performChanges({
|
||||
PHAssetChangeRequest.deleteAssets([asset] as NSFastEnumeration)
|
||||
}, completionHandler: completion)
|
||||
}
|
||||
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) {
|
||||
PHPhotoLibrary.shared().performChanges({
|
||||
PHAssetChangeRequest.deleteAssets(assets as NSFastEnumeration)
|
||||
}, completionHandler: completion)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private func getThumbnail(
|
||||
mediumId: String,
|
||||
|
Loading…
x
Reference in New Issue
Block a user