Try MAXST AR Fusion Tracker Now ✨

QR / Barcode Reader

It recognizes QR code and Barcode.

Create Instants
Start / Stop Reader
Use Read Information

Create Instants

>QR_BarcodeViewController.swift

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

Start / Stop Reader

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

>QR_BarcodeViewController.swift

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

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

Use Read Information

When you point the camera to QR code and Barcode, the code name will be 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()
    
   let backgroundImage:MasTrackedImage = trackingState.getImage()
        let backgroundProjectionMatrix:matrix_float4x4 = cameraDevice.getBackgroundPlaneProjectionMatrix()
        
        if let cameraQuad = backgroundCameraQuad {
            cameraQuad.draw(image:backgroundImage, projectionMatrix: backgroundProjectionMatrix)
        }
    
    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))
}