title: AVCaptureMetadataOutputObjectsDelegate method not called
body: <p>I have a ViewController that continuously scans for QR codes and implements <code>AVCaptureMetadataOutputObjectsDelegate</code> to retrieve the metadata output.</p>
  
  <pre><code>class ScanViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate {
  
      var captureSession = AVCaptureSession()
      var videoPreviewLayer: AVCaptureVideoPreviewLayer?
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          // Get the back-facing camera for capturing videos
          let deviceDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInDualCamera], mediaType: AVMediaTypeVideo, position: .back)
  
          guard let captureDevice = deviceDiscoverySession?.devices.first else {
              print("Failed to get the camera device")
              return
          }
  
          do {
              // Get an instance of the AVCaptureDeviceInput class using the previous device object.
              let input = try AVCaptureDeviceInput(device: captureDevice)
  
              // Set the input device on the capture session.
              captureSession.addInput(input)
  
              // Initialize a AVCaptureMetadataOutput object and set it as the output device to the capture session.
              let captureMetadataOutput = AVCaptureMetadataOutput()
              captureSession.addOutput(captureMetadataOutput)
  
              // Set delegate and use the default dispatch queue to execute the call back
              captureMetadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
              captureMetadataOutput.metadataObjectTypes = [AVMetadataObjectTypeQRCode]
  
          } catch {
              // If any error occurs, simply print it out and don't continue any more.
              print(error)
              return
          }
  
          // Initialize the video preview layer and add it as a sublayer to the viewPreview view's layer.
          videoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
          videoPreviewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
          videoPreviewLayer?.frame = view.layer.bounds
          view.layer.addSublayer(videoPreviewLayer!)
  
          // Start video capture.
          captureSession.startRunning()
      }
  
      func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
          print("in function of extension")
          // Check if the metadataObjects array is not nil and it contains at least one object.
          if metadataObjects.count == 0 {
              print("nada qr code")
              return
          }
  
          // Get the metadata object.
          let metadataObj = metadataObjects[0] as! AVMetadataMachineReadableCodeObject
  
          if metadataObj.type == AVMetadataObjectTypeQRCode {
              if metadataObj.stringValue != nil {
                  print(metadataObj.stringValue)
              }
          }
      }
  }
  </code></pre>
  
  <p>But for some reason the delegate callback doesn't get called. In <a href="https://www.appcoda.com/barcode-reader-swift/" rel="nofollow noreferrer">the tutorial I'm following</a>, it runs perfectly. </p>
  
  <p>Hopefully someone can provide any words of assistance. Anything would be immensely helpful to get me on the right track. Thanks so much in advance.</p>