QR and Barcode Scanning
Implement QR code and barcode scanner in your Ionic app. Also, generate your own QR code and share with others
Last updated
Implement QR code and barcode scanner in your Ionic app. Also, generate your own QR code and share with others
Last updated
A Barcode is a machine-readable optical label that contains information about the item to which it is attached. This is mostly used to catalog products in large warehouses, or departmental stores etc.
A QR code consists of black squares arranged in a square grid on a white background, which can be read by an imaging device such as a camera, and processed to return information like a website URL. Most mobile devices today have QR code scanners inbuilt, and they return the response on the screen.
This functionality requires Cordova plugin: phonegap-plugin-barcodescanner
.The Barcode Scanner Plugin opens a camera view and automatically scans a barcode/ QR code, returning the data back to you.
Install the plugin using
Import the plugin in your page using
Barcode / QR code scanning functionality can be found in Ionic 5 Full App at src/app/pages/addons3/bar-code
The scanning function can be simply called with
This opens the camera. When you point the camera to a valid barcode / QR code, it scans the code and returns the data in success
You can use several options in the scan
method
The plugin creates the object barcodeScanner
with the method encode(type, data, success, fail)
.
Supported encoding types:
TEXT_TYPE
EMAIL_TYPE
PHONE_TYPE
SMS_TYPE
Created QR Code appears in a separate page, and can be shared
Encoding data has a known issue in iOS with Webview. We are keeping this as a // TODO for upcoming fix releases
Since iOS 10 it's mandatory to add a NSCameraUsageDescription
in the Info.plist
NSCameraUsageDescription
describes the reason that the app accesses the user's camera. When the system prompts the user to allow access, this string is displayed as part of the dialog box. If you didn't provide the usage description, the app will crash before showing the dialog. Also, Apple will reject apps that access private data but don't provide an usage description.
To add this entry you can use the edit-config
tag in the config.xml
like this:
For more info, please see the BarcodeScanner plugin docs.