How I can save scans to user's photo library?

Code Block
extension ViewController: VNDocumentCameraViewControllerDelegate, UIImagePickerControllerDelegate {
    func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinish scan: VNDocumentCameraScan) {
        for pageNumber in 0..<scan.pageCount {
            let image = scan.imageOfPage(at: pageNumber)
            print(image)
            //save
            hasPhoto = true
            UIImageWriteToSavedPhotosAlbum(image, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
            //UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
        }
        controller.dismiss(animated: true, completion: nil)
    }

Answers

Hello,

I'm not sure what issue you are encountering exactly, but what you have here looks approximately correct.

Things to keep in mind:
  1. You must set your ViewController as the VNDocumentCameraViewControllerDelegate.

  2. You need the "Privacy - Photo Library Additions Usage Description" key in your info.plist (or the "Privacy - Photo Library Usage Description" if you also need read access to the Photo Library).