AVCaptureVideoDataOutputSampleBufferDelegate.CaptureOutput not called
<p>I currently have a self-developed framework (MySDK), and an iOS app (MyApp) that uses MySDK.</p>

<p>Inside of MySDK, I have a class (Scanner) in MySDK that processes images from the video output of the device camera.</p>

<p>Here's a sample of my code:</p>

<p><strong>Scanner.swift</strong></p>

<pre><code>class Scanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate {

    var captureDevice : AVCaptureDevice?
    var captureOutput : AVCaptureVideoDataOutput?
    var previewLayer : AVCaptureVideoPreviewLayer?
    var captureSession : AVCaptureSession?

    var rootViewController : UIViewController?

    func scanImage (viewController: UIViewController)
    {
        NSLog("%@", "scanning begins!")

        if (captureSession == nil) { captureSession = AVCaptureSession() }

        rootViewController = viewController;

        captureSession!.sessionPreset = AVCaptureSessionPresetHigh

        let devices = AVCaptureDevice.devices()

        for device in devices {
            if (device.hasMediaType(AVMediaTypeVideo)) {
                if(device.position == AVCaptureDevicePosition.Back) {
                    captureDevice = device as? AVCaptureDevice
                }
            }
        }

        if (captureDevice != nil) {
            NSLog("%@", "beginning session!")

            beginSession()
        }
    }

    func beginSession()
    {
        if (captureSession == nil) { captureSession = AVCaptureSession() }
        if (captureOutput == nil) { captureOutput = AVCaptureVideoDataOutput() }
        if (previewLayer == nil) { previewLayer = AVCaptureVideoPreviewLayer() }

        let queue = dispatch_queue_create("myQueue", DISPATCH_QUEUE_SERIAL);

        captureOutput!.setSampleBufferDelegate(self, queue: queue)
        captureOutput!.videoSettings = [kCVPixelBufferPixelFormatTypeKey as NSString: Int(kCVPixelFormatType_32BGRA)]

        captureSession!.addInput(try! AVCaptureDeviceInput(device: captureDevice))
        captureSession!.addOutput(captureOutput)

        previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
        previewLayer!.frame = rootViewController!.view.layer.frame

        rootViewController!.view.layer.addSublayer(previewLayer!)

        captureSession!.startRunning()
    }

    func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBufferRef!, fromConnection connection: AVCaptureConnection!)
    {
        NSLog("%@", "captured!")
    }
}
</code></pre>

<p>Inside MyApp, I have a ViewController which implements an <code>IBAction</code>, in which the Scanner class is initialized, and the <code>scanImage</code> function is triggered.</p>

<p><strong>MyApp.m</strong>:</p>

<pre><code>- (IBAction)btnScanImage_TouchDown:(id)sender
{
    Scanner * scanner = [[Scanner alloc] init];

    [scanner scanImage:self];
}
</code></pre>

<p>The camera view comes up inside of the app, but the captureOutput function is never fired, and the console only contains these two lines:</p>

<pre><code>2016-03-07 11:11:45.860 myapp[1236:337377] scanning begins!
2016-03-07 11:11:45.984 myapp[1236:337377] beginning session!
</code></pre>

<p>Creating a standalone app, and embedding the code inside <strong>Scanner.swift</strong> into a ViewController works just fine; the captureOutput function fires properly.</p>

<p>Does anyone have any idea what I am doing wrong here?</p>