gpt4 book ai didi

ios - 使用 UIImagePickerController 选取图像后如何从 PhotoLibrary 中删除图像

转载 作者:行者123 更新时间:2023-11-29 05:37:51 24 4
gpt4 key购买 nike

我需要从 PhotoLibrary 中删除图像。我在应用程序中使用 UIImagePickerController 来拾取图像。在我的应用程序中使用此图像后,我需要从 iOS PhotoLibrary 中删除它。

我的代码片段

if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary)
{
var imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary;
imagePicker.allowsEditing = false
self.presentViewController(imagePicker, animated: true, completion: nil)
}


// MARK:- UIImagePickerControllerDelegate
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
pickedImage = image
saveImageToDisk(pickedImage)
/*
I need the logic to delete this image from PhotoLibrary here.
*/
self.dismissViewControllerAnimated(true, completion: nil)
refreshCollectionView()
}

最佳答案

只是为了补充上面的内容,对于 swift 3.0,这对我有用。

PHPhotoLibrary.shared().performChanges({
let imageAssetToDelete = PHAsset.fetchAssets(withALAssetURLs: imageUrls as! [URL], options: nil)
PHAssetChangeRequest.deleteAssets(imageAssetToDelete)
}, completionHandler: {success, error in
print(success ? "Success" : error )
})

关于ios - 使用 UIImagePickerController 选取图像后如何从 PhotoLibrary 中删除图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56862305/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com