I have implemented vision document scanner inside framework. When camera view controller is called and document captured. While save button tapped it should dismiss and return to viewController.
Here is the code inside framework:
public func showScanner(){
self.createTaskController()
// let scannerViewController = VNDocumentCameraViewController()
// scannerViewController.delegate = self
// present(scannerViewController, animated: true)
print("Called Build")
}
private func createTaskController(){
let scannerViewController = VNDocumentCameraViewController()
scannerViewController.delegate = self
self.clientView?.addChild(scannerViewController)
self.clientView?.view.addSubview(scannerViewController.view)
scannerViewController.didMove(toParent: clientView)
scannerViewController.dismiss(animated: true)
}
public func imageFromFile(result: @escaping (_ image: UIImage?) -> Void){
//the image
if imageNew != nil {
result(imageNew)
}
else{
//callback nil so the app does not pause infinitely if
//the error != nil
result(nil)
}
}
public func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) {
guard scan.pageCount >= 1 else {
controller.dismiss(animated: true)
return
}
let originalImage = scan.imageOfPage(at: 0)
let newImage = compressedImage(originalImage)
imageNew = newImage
print("new image::\(newImage.size)")
print("new imagei::\(newImage)")
controller.dismiss(animated: true)
}
public func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFailWithError error: Error) {
print(error)
controller.dismiss(animated: true)
}
public func documentCameraViewControllerDidCancel(_ controller: VNDocumentCameraViewController) {
controller.dismiss(animated: true)
}
func compressedImage(_ originalImage: UIImage) -> UIImage {
guard let imageData = originalImage.jpegData(compressionQuality: 1),
let reloadedImage = UIImage(data: imageData) else {
return originalImage
}
return reloadedImage
}
Here is the code where i have called framework inside sample project:
@IBAction func btnAction(_ sender: Any) {
A8Scan(self).showScanner()
p()
}
My issue is when tapping on save button it should dismiss camera controller (VNDocumentCameraViewController) and return to sample app. But, In my case its not returning.
Any help much appreciated pls...
You add it as a child here
then to remove do
OR
Dismiss
To send the image create a function inside the clientView and call it