iosswiftios13visionkit

iOS App Crashing in VisionKit framework iOS 13


I am using VisionKit framework for document capture introduced in iOS 13. It's wonderfull framework for capturing document. But in this framework at one point there are two buttons on navigation bar (Retake and Done) on navigation bar. When I click on those app is getting Crashed with below reason:-

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.'

I have tried to do this by returning preferredStatusBarUpdateAnimation to false. But it didn't resolve.

Here is code snippet:-

import UIKit
import VisionKit

class DetectDocumentViewController: UIViewController, VNDocumentCameraViewControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    @IBAction func tapMeAction(_ sender: UIButton) {
        let vc = VNDocumentCameraViewController()
        vc.delegate = self
        present(vc, animated: true)
    }

    func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) {
        print("Found \(scan.pageCount)")

        for i in 0 ..< scan.pageCount {
            let img = scan.imageOfPage(at: i)
            print(img)
            // ... your code here
        }
        controller.dismiss(animated: true, completion: nil)
    }

    func documentCameraViewControllerDidCancel(_ controller: VNDocumentCameraViewController) {
        controller.dismiss(animated: true)
    }

    func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFailWithError error: Error) {
        print(error)
        controller.dismiss(animated: true)
    }
}

Is there any way to resolve this issue to prevent it from Crash?


Solution

  • It is an iOS 13 internal issue. Now it has resolved in iOS 13.1 please run your project in iOS 13.1. It will work fine. Please check iOS 13 bug fixes.