QRScannerController

class QRScannerController : UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate

This controller handles all the AV capture operation for QR scanning and talks to the QR view.

  • Capture session for QR scanner view.

    Declaration

    Swift

    var captureSession: AVCaptureSession?
  • This closure is triggered when a QR code has been detected

    Declaration

    Swift

    var onQRCodeDetected: (() -> Void)?
  • This var is used as a listener telling what to do after the scanning of the QR is completed.

    Declaration

    Swift

    var qrlistener: QrScanner?
  • Front camera device input.

    Declaration

    Swift

    var frontCameraInput: AVCaptureDeviceInput?
  • Back camera device input.

    Declaration

    Swift

    var backCameraInput: AVCaptureDeviceInput?
  • Third-party lib for QR code reading.

    Declaration

    Swift

    let reader: QRReader
  • Lock to synchronize access to ZXing library.

    Declaration

    Swift

    let zxingLock: DispatchSemaphore
  • Bool value to check if the capturing of the QR code is done.

    Declaration

    Swift

    var isCapture: Bool
  • Checks if the seeion set of av capture is done or not

    Declaration

    Swift

    var sessionSetupCompleted: Bool
  • The Capture session and the camera inputs are set up in the viewDidLoad function.

    Declaration

    Swift

    override func viewDidLoad()
  • The Capture session and the camera inputs are set up in the viewWillAppear function.

    Declaration

    Swift

    override func viewWillAppear(_ animated: Bool)
  • This function captures the output from the camera and processes the sample buffer.

    • - output: The AVCaptureOutput object.
    • - sampleBuffer: The CMSampleBuffer object containing the captured video frame.
    • - connection: The AVCaptureConnection object.

    Declaration

    Swift

    func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection)
  • Sets up the AVCaptureSession and adds the video preview layer to the view.

    Declaration

    Swift

    func setupCaptureSession()
  • Starts the camera session for qr scan. If the camera session is already running, it will not start the session again. If the AVCaptureSession has not been setup, it will setup the session. If the current SDK state is not in qr scanning mode, it will not start the camera session.

    Declaration

    Swift

    func startCameraSession()
  • Processes the sample buffer to detect and decode the QR code.

    Declaration

    Swift

    func processSampleBuffer(_ sampleBuffer: CMSampleBuffer)

    Parameters

    sampleBuffer

    The CMSampleBuffer object containing the captured video frame.

  • Processes the QR code result by trying to extract SensePrintInfo from given QR code bytes.

    Declaration

    Swift

    func processQRCodeResult(_ result: Data)

    Parameters

    result

    The Data object representing the QR code bytes.

  • Sets up the QR listener to listen to the QR code scanning events.

    Declaration

    Swift

    func setUpQrListener(listener: QrBytesListener)

    Parameters

    listener

    The QrBytesListener object.

  • Get the SensePrint bytes from SDK.

    Declaration

    Swift

    func parseAndProcessSensePrint(_ bytes: [UInt8]) async throws -> SensePrintInfo?

    Parameters

    bytes

    The UInt8 array representing the QR code bytes.

    Return Value

    The SensePrintInfo object.

  • Stops the AVCaptureSession and sets it to nil.

    Declaration

    Swift

    func stopScan()
  • Adjusts the zoom level of the camera.

    Declaration

    Swift

    func adjustZoom(scale: CGFloat)

    Parameters

    scale

    The scale factor for zooming.