How to make VNDocumentCameraViewController forget previous scans?

204 views Asked by At

By displaying the VNDocumentCameraViewController on iOS it automatically stores previous scans. This can be problematic for users who don't realize they are adding already scanned documents to their current scan.

Looking at the official VisionKit documentation I don't see any reference to how to do so that when doing viewController?.present(scannerController, animated: true).

How can I achieve that?

1

There are 1 answers

0
svprdga On

The solution to this problem is to create one instance at a time.

In my case, I had the following defined at the beginning of the class:

let scannerController: VNDocumentCameraViewController = VNDocumentCameraViewController()

So every time I wanted to display it I just called viewController?.present(scannerController, animated: true).

The solution is to instantiate VNDocumentCameraViewController every time you want to use it, this way a "new" view is started with no traces of previous scans:

let viewController : UIViewController? = UIApplication.shared.delegate?.window??.rootViewController
let scannerController = VNDocumentCameraViewController()
scannerController.delegate = self
viewController?.present(scannerController, animated: true)