QR / Barcode Scanner
QR / Barcode Scanner recognizes QR / Barcode.
Create Instants
Start / Stop Scanner
Use Scanning Information
Create Instants
>QR_BarcodeViewController.swift
var cameraDevice:MasCameraDevice = MasCameraDevice() var trackingManager:MasTrackerManager = MasTrackerManager()
Start / Stop 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() ... }
Use Scanning Information
When you point the camera to QR / 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)) }