Search code examples
iosobjective-ciphonephassetphphotolibrary

Dsiable Authorization request when deleting PHAsset


I have an application that deletes photos from the camera roll. This wipe is initiated remotely. Due to this if a wipe is initiated and the user is not at their phone they it will not wipe because you need to authorize the delete for each image.

Now I've read this is not possible in different questions. However, is it possible to request authorization to the phones photo library just as is done with geolocation when the application finishes loading on the first launch. Would this grant authorization for deleting without the need to confirm for every photo?

This is how I'm currently deleting the photos, it works fine apart from the need to confirm deletion of every image

         PHFetchResult *asset = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage 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(@"WIPE SUCCESSFUL");
            }
        }];
    }];

Solution

  • It's not possible to delete any photos/videos through the provided APIs without the confirmation alert. There is no way around this.