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

StatusResponse
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

  1. Verify Permissions Early: Check Superfans.variables.device.permissions.camera before launching the scanner. If the user hasn't granted access, the experience will break abruptly.
  2. 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

  1. 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.
  2. 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.
  3. Permission Dependency: This action will fail immediately if the user has previously denied camera permissions. You should verify Superfans.variables.device.permissions.camera before calling this action to ensure a smooth UI flow.

Did this page help you?