Delete image from Photo Gallery
fetchAssets(withALAssetURLs) - will be deprecated, what to use instead?
how to get image URL that is being saved to PhotoLibrary?
You don’t. That is why it is deprecated! You get the asset’s localIdentifier
. This allows you to access the asset and delete it later.
Your completion handler is empty. That’s the problem. Write the completion handler and get the local identifier from the placeholder.
How to delete an image from photo library using UIImagePickerController
NSURL *url = [dict objectForKey:@"UIImagePickerControllerReferenceURL"] ;
PHPhotoLibrary *library = [PHPhotoLibrary sharedPhotoLibrary];
[library performChanges:^{
// Here assetsURLs is array of url's you want to delete
PHFetchResult *assetsToBeDeleted = [PHAsset fetchAssetsWithALAssetURLs:[NSArray arrayWithObject:url] options:nil];
[PHAssetChangeRequest deleteAssets:assetsToBeDeleted];
} completionHandler:^(BOOL success, NSError *error)
{
// Check error and success here
}];
How to delete an image from PhotoLibrary after i pick it up using UIImagePickerController
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 )
})
Delete a photo from the user's photo library?
Yes we can delete a photo. We can use PHAssetChangeRequest
for this operation.
From Apple:
A request to create, delete, change metadata for, or edit the content of a Photos asset, for use in a photo library change block.
class func deleteAssets(_ assets: NSFastEnumeration)
where assets:
An array of PHAsset objects to be deleted.
PHAssetChangeRequest.deleteAssets([assetToDelete])
So, you could use the above code to delete assets.
below is swift 3 code,
PHPhotoLibrary.shared().performChanges({
let imageAssetToDelete = PHAsset.fetchAssets(withALAssetURLs: imageUrls as! [URL], options: nil)
PHAssetChangeRequest.deleteAssets(imageAssetToDelete)
}, completionHandler: {success, error in
print(success ? "Success" : error )
})
How to delete image from my Custom gallery and then Refresh the gallery
before calling notifyDataSetChanged();
You should remove Deleted image from thumbnails
Bitmap[]
array. but if you can use List<Bitmap>
instead of that, the method will be like this :public void RemoveThumbnail(int position)
{
this.thumbnails.remove(position);
//notifyDataSetChanged() can be called in this method or after
//calling this method in MainActivity
notifyDataSetChanged();
}
otherwise this is something that removes thumbnail in specific position :
public void RemoveThumbnail(int position)
{
Bitmap[] temp = new Bitmap[thumbnails.length - 1];
int tempIndex = 0;
for (int i = 0 ; i < thumbnails.lenght ; i++)
{
if(i != position)
temp[tempIndex ++] = thumbnails[i];
}
thumbnails = temp;
//notifyDataSetChanged() can be called in this method or after
//calling this method in MainActivity
notifyDataSetChanged();
}
Related Topics
Uialertcontroller Visible Only When Viewdidappear Has Finished Its Call
Uiimageview .Scaleaspectfit and Autolayout Not Working Programmatically from Swift
Advise Where to Store Data for iOS App
Type 'Any' Has No Subscript Members in Swift 3 Xcode 8
Swift App Crashes on Real Device But Works on Simulator
Error in Facebook Login, iOS 9, Swift
Getting Uitableview Error "Unable to Dequeue a Cell with Identifier Cell"
How to Add Storyboard Viewcontroller into Swiftui Project
Get Total Include Months Between 2 Date in Swift
Add View as a Parameter to a Custom Viewmodifier
Which View Controller Should I Pass in My Swift Native Code for a Flutter Plugin
How to Set Up Array for Multi Annotations with Swift
How to Open a Local PDF File Using a Swiftui Button
Circular Button Becomes Rounded Rectangle After Size Increase
Swift Save Viewcontroller State Using Coder Beyond App Close
Using Simple Ping in Swift (Ios)