'Delete picture in delete gallery folder

I am trying to delete a photo from the photo gallery of the phone, but the deleted image was in the deleted directory, there is a way to delete the picture which is in the deleted directory of the phone?

There is my code :

-(void)deleteCaptureProcess{
   
    
    PHAsset *asset = nil;
    PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
    fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
    PHFetchResult *fetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:fetchOptions];
    if (fetchResult != nil && fetchResult.count > 0) {
        // get last photo from Photos
        asset = [fetchResult lastObject];
    }

    if (asset) {
        
        PHContentEditingInputRequestOptions *editOptions = [[PHContentEditingInputRequestOptions alloc] init];

        [asset requestContentEditingInputWithOptions:editOptions completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {

        if (contentEditingInput.fullSizeImageURL) {
               
                
    NSLog(@"¨PATH %@",contentEditingInput.fullSizeImageURL);
                
    NSArray *lines = [[NSString stringWithFormat:@"%@", contentEditingInput.fullSizeImageURL] componentsSeparatedByString: @"/"];
    NSString *imageNZma = lines[[lines count]-1];
                
    NSMutableArray *persons = [[NSMutableArray alloc]initWithCapacity:0];
    [persons addObject:contentEditingInput.fullSizeImageURL];
                
    __block PHAssetCollection *albumCollection = [[PHAssetCollection alloc] init];
    PHFetchOptions *albumOptions = [[PHFetchOptions alloc] init];
    [albumOptions setPredicate:[NSPredicate predicateWithFormat:@"estimatedAssetCount >= 0"]];
                
    NSLog(@"%@",albumOptions);
                
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
            // Request creating an asset from the image.
        PHAssetChangeRequest* createAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[UIImage imageNamed:imageNZma]];
             // Request editing the album.
        PHAssetCollectionChangeRequest* albumChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:albumCollection];
             // Get a placeholder for the new asset and add it to the album editing request.
        PHObjectPlaceholder* assetPlaceholder = [createAssetRequest placeholderForCreatedAsset];        [albumChangeRequest addAssets:@[ assetPlaceholder ]];
 } completionHandler:^(BOOL success, NSError* error) {
            NSLog(@"Finished adding asset. %@", (success ? @"Success" : error));
    }];
     
    __block PHObjectPlaceholder *assetPlaceholder = nil;
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
    PHAssetChangeRequest * request = [PHAssetChangeRequest creationRequestForAssetFromImage: [UIImage imageNamed:imageNZma]];
    assetPlaceholder = request.placeholderForCreatedAsset;
    } completionHandler:^(BOOL success, NSError *error) {
        NSLog(@"creation success %d - error: %@ - place: %@", success, error, assetPlaceholder);
    PHFetchResult * result = [PHAsset fetchAssetsWithLocalIdentifiers: @[assetPlaceholder.localIdentifier] options: nil];
    NSLog(@"Asset fetching: %@", result);
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges: ^{
                
    [PHAssetChangeRequest deleteAssets: @[asset]];

    } completionHandler:^(BOOL success, NSError *error) {
//                NSLog(@"deletion success %d - error: %@ - place: %@", success, error, assetPlaceholder);

   
            }];
        }];
                
        }
        
    }];
        
    }
}

So my question is : there is a way to delete directly the image from the deleted folder after the image in gallery was deleted ?

Thank for help



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source