Need help upgrading to Ionic Framework 4.0? Get assistance with our Enterprise Migration Services EXPLORE NOW

ZBar

Improve this doc

The ZBar Scanner Plugin allows you to scan 2d barcodes.

Requires Cordova plugin: cordova-plugin-cszbar. For more info, please see the zBar plugin docs.

Repo: https://github.com/tjwoon/csZBar

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-cszbar
    $ npm install --save @ionic-native/zbar@4
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { ZBar, ZBarOptions } from '@ionic-native/zbar';

constructor(private zbar: ZBar) { }

...

let options: ZBarOptions = {
      flash: 'off',
      drawSight: false
    };

this.zbar.scan(options)
   .then(result => {
      console.log(result); // Scanned code
   })
   .catch(error => {
      console.log(error); // Error message
   });

Instance Members

scan(options)

Open the scanner

Param Type Details
options ZBarOptions

Scan options

Returns: Promise<any> Returns a Promise that resolves with the scanned string, or rejects with an error.

ZBarOptions

Param Type Details
text_title string

A string representing the title text (Android only). Default: "Scan QR Code"

(optional)
text_instructions string

A string representing the instruction text (Android only). Default: "Please point your camera at the QR code."

(optional)
camera string

A string defining the active camera when opening the scanner. Possible values: "front", "back" Default: "back"

(optional)
flash string

A string defining the state of the flash. Possible values: "on", "off", "auto" Default: "auto"

(optional)
drawSight boolean

A boolean to show or hide a line in the center of the scanner. Default: true

(optional)

API

Native

General