title: Taro.scanCode(option)
sidebar_label: scanCode
Opens the code scanning interface in the app to scan the code.
Reference
Type
(option: Option) => Promise<SuccessCallbackResult>
Parameters
Option
Property |
Type |
Required |
Description |
onlyFromCamera |
boolean |
No |
Indicates whether to allow to scan code with camera only |
scanType |
("barCode" | "qrCode" | "datamatrix" | "pdf417")[] |
No |
Type of code to scan |
complete |
(res: any) => void |
No |
The callback function used when the API call completed (always executed whether the call succeeds or fails) |
fail |
(res: any) => void |
No |
The callback function for a failed API call |
success |
(res: Result) => void |
No |
The callback function for a successful API call |
SuccessCallbackResult
Property |
Type |
Description |
charSet |
string |
Character set of code to scan |
path |
string |
If the scanned code is the QR code of the current Mini Program, this field is returned, and the content is the path carried by the QR code. |
rawData |
string |
Base64 encoded raw data |
result |
string |
Content of code to scan |
scanType |
"QR_CODE" | "AZTEC" | "CODABAR" | "CODE_39" | "CODE_93" | "CODE_128" | "DATA_MATRIX" | "EAN_8" | "EAN_13" | "ITF" | "MAXICODE" | "PDF_417" | "RSS_14" | "RSS_EXPANDED" | "UPC_A" | "UPC_E" | "UPC_EAN_EXTENSION" | "WX_CODE" | "CODE_25" |
Type of code to scan |
errMsg |
string |
Call result |
ScanType
Valid values of object.scanType
Property |
Description |
barCode |
Barcode |
qrCode |
QR code |
datamatrix |
Data Matrix code |
pdf417 |
PDF417 barcode |
QRType
Valid values of res.QRType
Property |
Description |
QR_CODE |
QR code |
AZTEC |
Barcode |
CODABAR |
Barcode |
CODE_39 |
Barcode |
CODE_93 |
Barcode |
CODE_128 |
Barcode |
DATA_MATRIX |
QR code |
EAN_8 |
Barcode |
EAN_13 |
Barcode |
ITF |
Barcode |
MAXICODE |
Barcode |
PDF_417 |
QR code |
RSS_14 |
Barcode |
RSS_EXPANDED |
Barcode |
UPC_A |
Barcode |
UPC_E |
Barcode |
UPC_EAN_EXTENSION |
Barcode |
WX_CODE |
QR code |
CODE_25 |
Barcode |
Sample Code
// Allow to scan code with camera and select code from albums
Taro.scanCode({
success: (res) => {
console.log(res)
}
})
// Only allow to scan code with camera
Taro.scanCode({
onlyFromCamera: true,
success: (res) => {
console.log(res)
}
})
API Support
API |
WeChat Mini-Program |
H5 |
React Native |
Taro.scanCode |
✔️ |
✔️ |
✔️ |