my.scan
Call the scan QR code or bar code function.
Hint: after calling my.scan
API, the onHide()
and onShow()
lifecycle callback function of App
and Page
will be executed. The following is the executing sequence:
App.onHide()
-> Page.onHide()
-> App.onShow()
-> Page.onShow()
.
Sample Code
copy
Page({
scan() {
my.scan({
type: 'qr',
success: (res) => {
my.alert({ title: res.code });
},
});
}
})
Parameters
Property | Type | Required | Description |
type | String | No | Type for scanning (qr by default): 1. qr : two-dimensional QR scanning frame. 2. bar : Linear barcode scanning frame. |
hideAlbum | Boolean | No | Hide album entry or not. If it is false , there will be an entry for user to select a picture from the album as the scanned picture. Otherwise, user will use camera to scan the content directly. By default, its value is 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 (to be executed upon either call success or failure). |
Success Callback Function
The incoming parameter is of the Object type with the following attributes:
Property | Type | Description |
code | String | Data returned from scanning. |
qrCode | String | QR code data returned from scanning. |
barCode | String | Bar code data returned from scanning. |
Error Code
Error | Description |
10 | User cancellation. |
11 | Operation failure. |