iosswiftqr-codeavcapturesessionavcaptureoutput

How to stop captureOutput in iOS app


I found tutorial for working with QR codes - here it is. Using this method i can get image from device camera and find QR code there.

The problem is that when I change ViewController and even stop the AVCaptureSession - it seems that my camera is still working and device is searching for QR code. So how should I disable captureOutput method?


Solution

  • I downloaded the demo project and doing

     self.captureSession?.stopRunning()
    

    works just fine for me

    fullCode

    func captureOutput(captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [AnyObject]!, fromConnection connection: AVCaptureConnection!) {
    
            // Check if the metadataObjects array is not nil and it contains at least one object.
            if metadataObjects == nil || metadataObjects.count == 0 {
                qrCodeFrameView?.frame = CGRectZero
                messageLabel.text = "No barcode/QR code is detected"
                return
            }
                    self.captureSession?.stopRunning()
    

    I set a breakPoint at the start of this function and it's not called anymore once the first QRCode is found.