Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// presenting VNDocumentCameraViewController
let scanVC = VNDocumentCameraViewController()
scanVC.delegate = self
present(scanVC, animated: true)
// VNDocumentCameraViewControllerDelegate conformance
extension DocumentsScannerViewController: VNDocumentCameraViewControllerDelegate {
func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) {
var documentImages: [UIImage] = []
for page in 0...scan.pageCount-1 {
let image = scan.imageOfPage(at: page)
controller.dismiss(animated: true, completion: nil)
finishedScanningDocuments(images: documentImages)
func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFailWithError error: Error) {
showError(message: "Something unexpected happened, please try again later")
controller.dismiss(animated: true)
func documentCameraViewControllerDidCancel(_ controller: VNDocumentCameraViewController) {
controller.dismiss(animated: true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment