my.scan opens the built-in scanner to read QR codes or barcodes. You can choose scan type (QR or bar) and whether to hide the album entry so the user scans only with the camera.
function scan() {
my.scan({
type: "qr",
success: (res) => {
my.alert({
title: "Scanned",
content: res.code || res.qrCode || res.barCode,
});
},
fail: (err) => {
my.alert({ content: "Scan failed: " + JSON.stringify(err) });
},
});
}
| Property | Type | Required | Description |
|---|---|---|---|
type | String | No | Scan type (default qr):• qr – QR code• bar – Barcode |
hideAlbum | Boolean | No | If false, user can pick an image from the album to scan. If true, only camera scan is used. Default false. |
success | Function | No | Callback function upon call success. |
fail | Function | No | Callback function upon call failure. |
complete | Function | No | Callback function upon call completion. |
The success callback receives an Object with:
| Property | Type | Description |
|---|---|---|
code | String | Data returned from scanning (generic). |
qrCode | String | QR code data returned from scanning. |
barCode | String | Barcode data returned from scanning. |
| Error | Description |
|---|---|
10 | User cancelled. |
11 | Operation failure. |