Try MAXST AR Fusion Tracker Now ✨

QR / Barcode Reader

QR / Barcode Reader recognizes QR code and Barcode.

Create Instants
Start / Stop Scanner
Use Scanning Information

Create Instants

>QR_BarcodeViewController.swift

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

Start / Stop Reader

To start or stop the 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 illuminate QR code or Barcode, the code name is displayed on the screen. Refer to the following code to use the Read information.

>QR_BarcodeViewController.swift

func draw(in view: MTKView) {
    ...
    
    let backgroundImage:MasTrackedImage = trackingState.getImage()
    var backgroundProjectionMatrix:matrix_float4x4 = cameraDevice.getBackgroundPlaneProjectionMatrix()
    
    if let cameraQuad = backgroundCameraQuad {
        cameraQuad.setProjectionMatrix(projectionMatrix: backgroundProjectionMatrix)
        cameraQuad.draw(commandEncoder: commandEncoder, image: backgroundImage)
    }
    
    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)
    }
    ...
}