Open Camera
Opens the device camera interface specifically configured for scanning.
Description
The OpenCamera({type:scan}) action launches the native camera view in "scanner mode." This is specifically optimized for recognizing barcodes or QR codes. Unlike a standard photo capture, this interface typically includes a viewfinder overlay and automatically processes the code once it enters the frame.
Function Signature
await Superfans.actions.openCamera({ type: "scan" })Structure of Response
| Status | Response |
|---|---|
| Success | { "status": "success", "message": "Action executed successfully" } |
| Cart not accessible | { "status": "error", "errorId": 400, "message": "Action not executed"} |
| Unexpected Error | { "status": "error", "errorId": 500, "errorHandle": "unknown-error", "message": "Something unexpected happened" } |
Example Usage
async function handleScan() {
try {
await Superfans.actions.openCamera({ type: "scan" });
} catch (error) {
console.error("Scan error", error);
}
}Best Practices
- Verify Permissions Early: Check
Superfans.variables.device.permissions.camerabefore launching the scanner. If the user hasn't granted access, the experience will break abruptly. - Avoid "Scanner Loops": After a successful scan, navigate the user to the relevant product or result page immediately. Avoid returning them back to the camera unless they explicitly choose to "Scan Another Item."
Caveats
- Lighting & Clarity: Scanning performance is highly dependent on environmental factors; poor lighting or blurry camera lenses can cause the action to hang or fail to recognize codes.
- Format Support: The scanner is optimized for standard formats (QR, EAN, UPC). Custom or proprietary 2D codes may not be supported by the native underlying library.
- Permission Dependency: This action will fail immediately if the user has previously denied camera permissions. You should verify
Superfans.variables.device.permissions.camerabefore calling this action to ensure a smooth UI flow.
Updated 14 days ago
Did this page help you?