Develop Secure Code
BarcodeScanner Constants
BarcodeScanner Data Types
getBarcodeScanner()
isAvailable()
scan(options)
dismiss()
beginCapture(options) (Legacy)
resumeCapture() (Legacy)
endCapture() (Legacy)
scan(options)Use this function to start scanning barcodes.
1import { getBarcodeScanner } from 'lightning/mobileCapabilities';
2scan(options: BarcodeScannerOptions): Promise<Object>options—(Required) A BarcodeScannerOptions object to configure the scanning session.A Promise object that resolves as an array of Barcode objects with the scanned barcode details.
A rejected promise returns a BarcodeScannerFailure.
This function allocates scanner resources. To release the resources when scanning is complete, pair it with dismiss().
1myScanner
2 .scan(scanningOptions)
3 .then((resultsArray) => {
4 // Do something with the result of the scan
5 for (let singleResult in resultsArray) {
6 console.log(singleResult);
7 this.scannedBarcodes.push(singleResult.value);
8 }
9 })
10 .catch((error) => {
11 // Handle cancellation and scanning errors here
12 console.error(error);
13 })
14 .finally(() => {
15 myScanner.dismiss();
16 });When this function is called, a mobile OS scanning user interface is displayed on the mobile device. The user can point their camera at a barcode and wait for the barcode to be recognized.
then clause.catch clause.BarcodeScannerFailure.code value of userDismissedScanner.dismiss().dismiss(), in a finally clause.See Also