QR / Barcode Scanner

QR / Barcode Scanner recognizes QR / Barcode.

Create Instants
Starting / Stopping the Scanner
Using the Scanning Information

Create Instants

>QR_BarcodeViewController.swift

var cameraDevice:MasCameraDevice = MasCameraDevice()
var backgroundRenderer:MasBackgroundRenderer = MasBackgroundRenderer()
var trackingManager:MasTrackerManager = MasTrackerManager()

Starting / Stopping the Scanner

To start / stop Scanner, refer to the following code.

>QR_BarcodeViewController.swift

@objc func resumeAR()
{
    ...
    trackingManager.start(.TRACKER_TYPE_CODE_SCANNER)
}

@objc func pauseAR()
{
    trackingManager.stopTracker()
    ...
}

Using the Scanning Information

When you illuminate QR / Barcode, the code name is displayed on the screen. Refer to the following code to use the scanning information.

>QR_BarcodeViewController.swift

override func glkView(_ view: GLKView, drawIn rect: CGRect) {
        
    ...
    
    let trackingState:MasTrackingState = trackingManager.updateTrackingState()
    
    guard let backgroundTexture = backgroundRenderer.getBackgroundTexture() else {
        return
    }
    backgroundRenderer.begin(backgroundTexture)
    backgroundRenderer.renderBackgroundToTexture()
    backgroundRenderer.end()
    
    backgroundQuad.draw(texture: backgroundTexture, projectionMatrix: cameraDevice.getBackgroundPlaneProjectionMatrix())
    
    glEnable(GLenum(GL_DEPTH_TEST))
    
    let codeScanResult:String = trackingState.getCodeScanResult()
    
    if codeScanResult != "" {
        let objectData:Data = codeScanResult.data(using: String.Encoding.utf8)!
        let json = try! JSONSerialization.jsonObject(with: objectData, options: JSONSerialization.ReadingOptions.mutableContainers) as! [String: String]
    
        self.formatLabel.text = json["Format"]
        self.codeLabel.text = json["Value"]
        
        trackingManager.stopTracker()
        self.scanButton.alpha = 1.0
        self.scanButton.isEnabled = true
        self.scanButton.setTitle("Start Scan", for: .normal)
    }
    
    glDisable(GLenum(GL_DEPTH_TEST))
}