QR Scanner
Scan QR codes using the device camera, with optional real-time validation.
Access: startiapp.QrScanner
For a step-by-step guide to scanning QR codes — including validation and continuous scanning — see Scan QR Codes.
Methods
scan(options?): Promise<string | null>
Opens the QR code scanner. Returns the scanned value when a code is read, or null if the scanner is already running.
When a validation function is provided, the scanner stays open and keeps scanning until the validation function returns true. This is useful for rejecting invalid codes without closing the scanner.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| options | QrScannerOptions | No | Scanner configuration and optional validation |
Returns: Promise<string | null> —The scanned QR code string, or null if a scan is already in progress.
Example:
// Basic scan
const result = await startiapp.QrScanner.scan();
if (result) {
console.log("Scanned:", result);
}// Choose front camera, hide switch button
const result = await startiapp.QrScanner.scan({
cameraFacing: "front",
showCameraSwitchButton: false,
});// With async validation (scanner stays open until valid code is scanned)
const validResult = await startiapp.QrScanner.scan({
validation: async (scannedValue) => {
// e.g. check against your server
const response = await fetch(`/api/validate?code=${scannedValue}`);
return response.ok;
},
});
console.log("Valid code scanned:", validResult);// With synchronous validation
const result = await startiapp.QrScanner.scan({
validation: (scannedValue) => {
return scannedValue.startsWith("VALID_");
},
});stop(): Promise<void>
Stops the QR code scanner and closes the camera view.
Returns: Promise<void>
Example:
await startiapp.QrScanner.stop();isCameraAccessGranted(): Promise<boolean>
Checks whether camera access has been granted.
Returns: Promise<boolean> —true if camera access is granted.
Example:
const granted = await startiapp.QrScanner.isCameraAccessGranted();
if (!granted) {
await startiapp.QrScanner.requestCameraAccess();
}requestCameraAccess(): Promise<void>
Requests camera permission from the user. Shows the platform's native permission dialog.
Returns: Promise<void>
Example:
await startiapp.QrScanner.requestCameraAccess();Events
qrCodeScanned
Fired each time a QR code is successfully scanned. This event fires even when using the validation option, allowing you to react to every scan attempt.
Event data: string —The scanned QR code value.
Example:
startiapp.QrScanner.addEventListener("qrCodeScanned", (event) => {
console.log("Code scanned:", event.detail);
});qrScannerClosed
Fired when the QR scanner is closed (either by the user or programmatically).
Event data: None.
Example:
startiapp.QrScanner.addEventListener("qrScannerClosed", () => {
console.log("Scanner was closed");
});Types
QrScannerOptions
type QrScannerOptions = {
/** Whether to show the camera preview while scanning. Default: true. */
showCameraPreview?: boolean;
/** Which camera to use. Default: "back". */
cameraFacing?: "front" | "back";
/** Whether to show the camera switch button. Default: true. */
showCameraSwitchButton?: boolean;
/** Optional validation function. Scanner stays open until it returns true. */
validation?: (scannedValue: string) => boolean | Promise<boolean>;
};