Clear the scanned images cache in VNDocumentCameraScan Swift

949 views Asked by At

I have used vision kit for document scanning. I'm able to scan and save the documents, but the old scanned images are shown on the bottom left corner of the screen after coming back to this screen after dismissal. How to clear the scan array after dismissal?

Code:

let vc = VNDocumentCameraViewController()

override func viewDidLoad() {
     super.viewDidLoad() 
     vc.delegate = self 
}

//Save button action in document VC

    func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) {
            print("Found \(scan.pageCount)")
            var imgArray: Array<UIImage> = []
            for i in 0 ..< scan.pageCount {
                let image = scan.imageOfPage(at: i)
                imgArray.append(image)
            }
            dismiss(animated: true) {
                self.getFileName(img: imgArray)
            }
        }

Marked the scanned images icon at the bottom left

1

There are 1 answers

0
andrey.krukovskiy On BEST ANSWER

Seems, you keep link to instance of VNDocumentCameraViewController in vc constant of your view controller object. And when you show it second time, the same instance is reused.

Try create and present it like this:

func showDocumentCamera() {
   let vc = VNDocumentCameraViewController()
   vc.delegate = self
   present(vc, animated: true)
}