Delete image from user album. PHPhotoLibrary target C

In my application, I used edit pic and saved to a custom folder in Gallery called "Fab". Is there anything now to remove this image from the folder? I found another solution, but they need the resource URL. I used the Photos framework so how do I get the resource URL for a specific image for deletion?

+1
source share
2 answers
PHAsset *tempPhasset = [_arrImageForAssetCameraRoll objectAtIndex:index]; // here pass your PHasset that you want to delete . NSString *localStr=tempPhasset.localIdentifier; NSRange range = [localStr rangeOfString:@"/"]; NSString *newString = [localStr substringToIndex:range.location]; NSString *appendedString=[NSString stringWithFormat:@"%@%@%@",@"assets-library://asset/asset.JPG?id=",newString,@"&ext=JPG"]; NSLog(@"%@ phasset ",appendedString); NSURL *deleteurl = [NSURL URLWithString:appendedString]; NSArray *arrDelete = [[NSArray alloc] initWithObjects:deleteurl , nil]; PHFetchResult *asset = [PHAsset fetchAssetsWithALAssetURLs:arrDelete options:nil]; [asset enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSLog(@"%@",[obj class]); [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ BOOL req = [obj canPerformEditOperation:PHAssetEditOperationDelete]; if (req) { NSLog(@"true"); [PHAssetChangeRequest deleteAssets:@[obj]]; } } completionHandler:^(BOOL success, NSError *error) { NSLog(@"Finished Delete asset. %@", (success ? @"Success." : error)); if (success) { NSLog(@"delete successfully"); }else{ NSLog(@"delete Cancel"); } }]; 

Any requests for my code then put a comment. Happy coding.

+2
source

Try this code below

 ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; [library writeImageToSavedPhotosAlbum:[viewImage CGImage] orientation:(ALAssetOrientation)[viewImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){ if (error) { NSLog(@"error"); } else { NSLog(@"url %@", assetURL); } }]; 

will return the url for the saved image.

+1
source

Source: https://habr.com/ru/post/1233767/


All Articles