Is there a way I can delete an image that is loaded into my app from a UIImagePickerController
?
I want to be able to delete the image from the user's photo library when the user performs a specific action.
I am prompting the user to choose a image from their library, then it gets loaded into my app at which point the app does some shnazzy animation, then actually deletes the image.
Please help!
Actually, you can delete photos saved by your app (saved to photo library with UIImageWriteToSavedPhotosAlbum API call).
The documented API
[ALAsset setImageData:metadata:completionBlock:]
works.1). Add an image "photo.jpg" to your project
2). Save an image to asset library:
3). Go to default gallery, you will find photo.jpg in your "Saved Photos" album.
4). Delete this image from asset library:
5). Go to default gallery, you will find photo.jpg has already been deleted.
Yes we can delete a photo. We can use
PHAssetChangeRequest
for this operation.where assets: An array of PHAsset objects to be deleted.
So, you could use the above code to delete assets.
below is swift 3 code,
Apple doesn't actually allow you to delete from the photo library through an API. The user has to actually go to the Photos app and delete it manually themselves. Apple does allow you write to the photo library:
But for deleting and editing/overriding an existing photo, Apple doesn't have anything like that right now.