isAvailable()

Use this function to determine whether scanner functionality is available.

Syntax 

1import { getBarcodeScanner } from 'lightning/mobileCapabilities';
2isAvailable(): Boolean

Parameters 

None.

Returns 

Returns true when used on a supported device, and false otherwise.

Usage 

Use this function to disable or hide scan features on platforms where scanning isn’t supported. For example:

1handleBeginScanClick(event) {
2  const myScanner = getBarcodeScanner();
3  if(myScanner.isAvailable()) {
4    // Perform scanning operations
5  }
6  else {
7    // Scanner not available
8    // Not running on hardware with a scanner, or some other context error
9    // Handle with message, error, beep, and so on
10  }
11}

This function is also useful to avoid entering complicated logic surrounding scanning when it’s guaranteed to fail. However, it isn’t required to check before attempting a scan. Either way, your code should handle errors such as attempting a scan on an unsupported device.