Opens the native camera to scan a QR code.
Configuration for the QR code scanning, including the title to display.
The QR code scanning result, containing the scanned code on success or status information.
Simple usage
import { CameraModule, isSuccess, isErrorResponse } from '@grabjs/superapp-sdk';
// Initialize the camera module
const camera = new CameraModule();
// Scan the QR code
const response = await camera.scanQRCode({ title: 'Scan Payment QR' });
// Handle the response
if (isSuccess(response)) {
switch (response.status_code) {
case 200:
console.log('QR code scanned:', response.result.qrCode);
break;
case 204:
console.log('User cancelled QR code scanning');
break;
}
} else if (isErrorResponse(response)) {
switch (response.status_code) {
case 403:
console.log('Camera permission not enabled');
// Advise user to enable camera permission in device settings
break;
default:
console.error(`Error ${response.status_code}: ${response.error}`);
}
} else {
console.error('Unhandled response');
}
JSBridge module for accessing the device camera.
Remarks
Provides access to native camera functionality including QR code scanning. This code must run on the Grab SuperApp's WebView to function correctly.
Example
ES Module:
Example
CDN (UMD):