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 / stop 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 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.

※ startTracker() should be called before

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

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