scanCode(params: Object)

Requires:
BaseKit≥2.3.2@ray-js/ray≥0.3.23
Platforms:
iOSAndroid
import { scanCode } from '@ray-js/ray';

// Promise usage
try {
  const res = await scanCode({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

Description

Launch the client scan UI for scanning. Note: On Android, only the result field is usable; other fields are meaningless.

Parameters

PropertyTypeRequiredDefaultDescriptionBaseKit Since
onlyFromCamerabooleanNofalseWhether to scan only using the camera; selecting images from the album is not allowed.-
isShowActionTitlebooleanNotrueWhether to show the action title (Android only)v3.3.3
isShowTorchbooleanNofalseWhether to display the flashlight (Android only)v3.3.3
isShowKeyboardbooleanNofalseWhether to show the input for the setup codev3.12.0
No-Custom text for the setup-code inputv3.12.0
customTipsstringNo-Custom prompt text (Android only)v3.3.3
scanTypestring[]No["barCode", "qrCode"]Scan type-
complete() => voidNo-Completion callback (executed on both success and failure)-
success(params: Object) => voidNo-Callback on successful API call-
fail(params: Object) => voidNo-Failure callback-
success callback parameters
PropertyTypeDescriptionBaseKit Since
resultstringScanned contentv3.2.6
scanTypestringType of the scanned codev3.2.6
charSetstringCharacter set of the scanned codev3.2.6
pathstringIf the scanned code is the current Mini Program QR code, this field is returned with the QR code’s path (may be absent).v3.2.6
rawDatastringRaw data, base64-encodedv3.2.6
fail callback parameters
PropertyTypeDescription
errorMsgstringError message
errorCodestring | numberError code
Error extension

Return Value

None

Examples

import { scanCode } from '@ray-js/ray'

// Open the client scan UI; after scanning, the callback returns the content and type (on Android only the result field is valid)
scanCode({
  onlyFromCamera: false,
  isShowActionTitle: true,
  isShowTorch: false,
  isShowKeyboard: false,
  scanType: ["barCode", "qrCode"],
  success: data => console.log("Scan result:", data.result, data.scanType),
  fail: error => console.error(error),
});