0

I tried for many hours now to try and get my application to work. The problem is that after the app detects a QR-code, it does not show the new view controller. It will perform a simple print statement in that new view controller to the log, but there is no new view controller present in the app. I tried many solutions already on Stackoverflow, but none seems to be helping in this specific case.

func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!) {
    captureSession.stopRunning()

    if let metadataObject = metadataObjects.first {
        let readableObject = metadataObject as! AVMetadataMachineReadableCodeObject;

        AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
        found(code: readableObject.stringValue);

    }
    let vc = infoViewController()
    self.present(vc, animated: true, completion: nil)

I Use the last to lines to point to the new infoViewController the app is supposed to go to after scanning a QR-code. The code in the infoViewController is as follows:

import UIKit

class infoViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        print("Hi")
}

The Log does show the print statement "Hi", but the application does not go to the infoViewController. The storyboard also has the infoViewController in it, with the class infoViewController selected.

Is there a detail that I'm missing currently?

Greetings

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Jelleko
  • 53
  • 1
  • 9

1 Answers1

0

First you have to select the infoViewController on your storyboard and in the Identity inspector, you have to add a Storyboard ID like this:

enter image description here

Then you have to present the infoViewController like this:

OperationQueue.main.addOperation {
    let infoViewController = self.storyboard?.instantiateViewController(withIdentifier: "infoViewController"
    self.present(infoViewController, animated: true)
}
pableiros
  • 14,932
  • 12
  • 99
  • 105