QR-/barcode scanner

Use this integration for a fast QR- and barcode scanning experience.

Introduction

This integration allows the app to scan QR- and barcodes in a fast and relieable way using the camera on the device.

Integration name: startiapp.QrScanner

Methods

scan

scan(options?: {
  validation?: (scannedValue: string) => boolean | Promise<boolean>,
  cameraFacing?: "front" | "back",
  showCameraSwitchButton?: boolean
}): Promise<string>

Opens the camera on the phone and starts scanning for QR- and barcodes. When the camera scans a code, it will be validated (if a validation function is provided). If validation passes or no validation is provided, the camera will be closed and the client user will be back on the website. If validation fails, scanning continues.

Parameters

  • options.validation (optional): A function to validate scanned codes. Return true to accept the code or false to continue scanning. Can be synchronous or asynchronous.
  • options.cameraFacing (optional): Which camera to use. "front" for the front-facing camera or "back" for the rear camera. Defaults to "back".
  • options.showCameraSwitchButton (optional): Whether to show a button that lets the user switch between front and back cameras while scanning. Defaults to true.

Examples

// Using a validation function to validate scanned QR codes
const validatedResult = await startiapp.QrScanner.scan({
  validation: async (scannedValue) => {
    // Simulate an async validation (e.g., server-side check)
    await new Promise(resolve => setTimeout(resolve, 1000));
    return scannedValue === "VALID_CODE"; // Only accept this specific code
  }
});
// Using a synchronous validation function
const validatedResult = await startiapp.QrScanner.scan({
  validation: (scannedValue) => {
    return scannedValue.startsWith("VALID_"); // Accept codes starting with "VALID_"
  }
});
// Using the front-facing camera
const result = await startiapp.QrScanner.scan({
  cameraFacing: "front"
});
// Hiding the camera switch button
const result = await startiapp.QrScanner.scan({
  showCameraSwitchButton: false
});

isCameraAccessGranted

isCameraAccessGranted(): Promise<boolean>

Returns a boolean indicating where access to the camera has been granted.

getCameraAccessState

getCameraAccessState(): Promise<"Unknown" | "Granted" | "Denied">

Returns a string indicating state of access to the camera:

  • Unknown means access has not been requested yet
  • Granted means access has been granted
  • Denied means access has been denied

requestCameraAccess

requestCameraAccess(): Promise<boolean>

Asks the user about access to the camera on the device. Returns a boolean indicating wether the call completed successfully or not. So the value can’t be used to determine if there are access to the camera. Here a following call to isCameraAccessGranted() is necessary.


Events

How to listen for events.

This module does not currently offer any events.