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 Objective-C. 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_BarcodeViewController.mm

- (void)viewDidLoad
{
    ...
    trackingManager = [[MasTrackerManager alloc] init];
    cameraDevice = [[MasCameraDevice alloc] init];
}

2.2 Start / Stop Reader

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

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

QR_BarcodeViewController.mm

- (void)resumeAR
{
    ...
    [trackingManager startTracker:TRACKER_TYPE_CODE_SCANNER];
}

- (void)pauseAR
{
    [trackingManager stopTracker];
    ...
}

2.3 Use Read Information

When you point the camera to QR code or Barcode, the code name will be displayed on the screen. Refer to the following code to use the Read information.

※ startTracker() should be called before

QR_BarcodeViewController.mm

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
    ...
    MasTrackingState *trackingState = [trackingManager updateTrackingState];
    
    MasTrackedImage *trackedImage = [trackingState getImage];
    [backgroundCameraQuad draw:trackedImage projectionMatrix:[cameraDevice getBackgroundPlaneProjectionMatrix]];
    
    glEnable(GL_DEPTH_TEST);
    
    NSString *codeScanResult = [trackingState getCodeScanResult];
    
    if(![codeScanResult isEqual: @""])
    {
        NSError* error;
        NSData *objectData = [codeScanResult dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:objectData options:NSJSONReadingMutableContainers error:&error];
        self.formatLabel.text = json[@"Format"];
        self.codeLabel.text =  json[@"Value"];;
        
        [trackingManager stopTracker];
        [self.scanButton setAlpha:1.0f];
        [self.scanButton setEnabled:YES];
        [self.scanButton setTitle:@"Start Scan" forState:UIControlStateNormal];
    }
    ...
}

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_BarcodeViewController.mm