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>
}): 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. Returntrueto accept the code orfalseto continue scanning. Can be synchronous or asynchronous.
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_"
}
});
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:
Unknownmeans access has not been requested yetGrantedmeans access has been grantedDeniedmeans 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
This module does not currently offer any events.