11

Exporing the new VNDocumentCameraViewController I cannot find any delegate or property to set the maximum number of scans.

Does anybody have a workaround or any idea I can implement to limit the number of scans in one go?

Hassy
  • 5,068
  • 5
  • 38
  • 63
  • Have you find a solution? I have the same question, want to limit for 2 scans only, but couldn't find a solution yet. The delegate is only notified when the user saves or cancel, so I believe its not going to be possible, not with visionKit at least. – Everton Carneiro Dec 01 '20 at 14:12

3 Answers3

2

I had the same issue, and I'm trying other alternatives. It's limited to 24 scans top. By default and it's not customizable

1

As of iOS 13 Apple doesn't currently support limiting the scan count.

See VNDocumentCameraViewController for the documentation for the class. The delegate VNDocumentCameraViewControllerDelegate doesn't have anything either.

If you want to use the native scanner your best bet is just picking the first scan once documentCameraViewController(_:didFinishWith:) is called.

Alternatively, you can have a look at WeScan.

MrHaze
  • 3,786
  • 3
  • 26
  • 47
-2

All you can do is call VNDocumentCameraViewControllerDelegate and add this delegate method:

func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) {
    // Process the scanned pages
    for pageNumber in 0..<scan.pageCount {

    }

    // You are responsible for dismissing the controller.
    controller.dismiss(animated: true)
}

In for loop you can add you limit and if the limit exceed you can stop scanning.

  • You only get access to scan.pageCount after you press the save button on the ViewController, you can take more scans then the limit you set before press save, so this doesn't going to work – Everton Carneiro Dec 01 '20 at 14:03