QR / Barcode Scanner

QR / Barcode Scanner recognizes QR / Barcode.

Create Instants
Start / Stop Scanner
Use Scanning Information

Create Instants

>QR_BarcodeViewController.mm

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

Start / Stop Scanner

To start / stop Scanner, refer to the following code.

>QR_BarcodeViewController.mm

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

- (void)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.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];
    }
    ...
}