我使用UIImagePickerController拾取图像后如何从PhotoLibrary中删除图像 [英] How to delete an image from PhotoLibrary after i pick it up using UIImagePickerController

查看:67
本文介绍了我使用UIImagePickerController拾取图像后如何从PhotoLibrary中删除图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从PhotoLibrary中删除图像.我在应用程序中使用UIImagePickerController来拾取图像.在应用程序中使用该图像后,我需要从iOS PhotoLibrary中删除该图像.

I need to delete the image from PhotoLibrary. I am using UIImagePickerController in my application to pick up the image. I need to delete this image from iOS PhotoLibrary after i use it in my application.

我的代码段

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,它对我有用.

Just to add to the above, For swift 3.0 this worked for me.

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

这篇关于我使用UIImagePickerController拾取图像后如何从PhotoLibrary中删除图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆