Try MAXST AR Fusion Tracker Now ✨

QR / Barcode Reader

QR / Barcode Reader recognizes QR code and Barcode.

Create Instants
Start / Stop Reader
Use Read Information

Create Instants

>QR_BarcodeViewController.mm

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

Start / Stop Reader

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

>QR_BarcodeViewController.mm

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

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

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.

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