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

PropertyType

Required

Description
typeStringNoType for scanning (qr by default):
1. qr: two-dimensional QR scanning frame.
2. bar: Linear barcode scanning frame.
hideAlbumBooleanNoHide 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.
successFunctionNoCallback function upon call success.
failFunctionNoCallback function upon call failure.
completeFunctionNoCallback 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:

PropertyTypeDescription
codeStringData returned from scanning.
qrCodeStringQR code data returned from scanning.
barCodeStringBar code data returned from scanning.

Error Code

ErrorDescription
10User cancellation.
11Operation failure.