QR / Barcode Reader iOS Tutorial

1. Overview
2. iOS Development
2.1 Create Instants
2.2 Start / Stop Reader
2.3 Use Read Information
3. Reference
3.1 API Reference
3.2 Sample


1. Overview

Start developing MAXST ARSDK QR/Barcode Tracker on iOS Platform. Refer to QR/Barcode Reader Introduction for detailed information.

Refer to Tracker Coordinate System to better understand 3D coordinate system of QR/Barcode Reader.

Prerequisite
QR/Barcode Reader Introduction
Tracker Coordinate System


2. iOS Development

Start developing on xCode using Swift. Refer to Requirements & Supports to find out which devices are supported.

ARSDK has to properly integrate on iOS UIViewController. Refer to Life Cycle documents for detail.


2.1 Create Instants

QR_BarcodeTrackerViewController.swift

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

2.2 Start / Stop Reader

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

※ To change the tracker, destroyTracker() should be called before

QR_BarcodeTrackerViewController.swift

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

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


2.3 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.

※ startTracker() should be called before

QR_BarcodeTrackerViewController.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)
    }
    ...
}

3. References

These are additional references to develop QR/Barcode Tracker


3.1 API Reference

Following documents explain classes and functions used to run QR/Barcode Tracker.

MaxstAR Class

TrackerManager Class

CameraDevice Class


3.2 Sample

For information regarding sample build and run of QR/Barcode Tracker, refer to Sample

QR_BarcodeTrackerViewController.swift