跳到主要内容
版本:v7

@capacitor/barcode-scanner

使用 Outsystems 条码库的 Capacitor 插件

安装

npm install @capacitor/barcode-scanner
npx cap sync

Android

条码扫描插件要求最低 Android SDK 目标版本为 26,这高于 Capacitor 应用的默认值。您可以在 android/variables.gradle 文件中更新此值。

ext {
minSdkVersion = 26
}

Note: Android with ZXING scanning library supports all formats, while MLKIT supports all except MAXICODE, RSS_14, RSS_EXPANDED and UPC_EAN_EXTENSION - using one of these in hint will default to scanning any format.

iOS

条码扫描器使用设备上的摄像头。请确保在 Info.plist 文件中配置了 Privacy - Camera Usage Description,以便您的应用可以访问设备的摄像头。

注意:搭载ZXING扫描库的安卓系统支持所有格式,而MLKIT支持除MAXICODERSS_14RSS_EXPANDEDUPC_EAN_EXTENSION之外的所有格式——在hint中使用其中一种格式将默认扫描任何格式。


API

定义条码扫描插件合约的接口。 要求实现 scanBarcode 方法,该方法使用给定选项启动条码扫描。

scanBarcode(...)

scanBarcode(options: CapacitorBarcodeScannerOptions) => Promise<CapacitorBarcodeScannerScanResult>
参数类型
options
CapacitorBarcodeScannerOptions

返回值:

Promise<CapacitorBarcodeScannerScanResult>


Type Aliases

CapacitorBarcodeScannerScanResult

定义从条码扫描返回的结果结构。

{ ScanResult: string; format: CapacitorBarcodeScannerTypeHint; }

CapacitorBarcodeScannerTypeHint

从 Html5Qrcode 扩展支持的格式,并添加特殊的 'ALL' 选项, 表示支持所有条码类型。 结合 Html5QrcodeSupportedFormats 和 OSBarcodeTypeHintALLOption 的类型定义,用于表示要扫描的条码类型的提示。


  Html5QrcodeSupportedFormats |{' '}
  CapacitorBarcodeScannerTypeHintALLOption

CapacitorBarcodeScannerOptions

定义配置条码扫描的选项。

{ hint: CapacitorBarcodeScannerTypeHint; scanInstructions?: string; scanButton?: boolean; scanText?: string; cameraDirection?: CapacitorBarcodeScannerCameraDirection; scanOrientation?: CapacitorBarcodeScannerScanOrientation; android?: { scanningLibrary?: CapacitorBarcodeScannerAndroidScanningLibrary; }; web?: { showCameraSelection?: boolean; scannerFPS?: number; }; }

Enums

Html5QrcodeSupportedFormats

成员
QR_CODE0
AZTEC1
CODABAR2
CODE_393
CODE_934
CODE_1285
DATA_MATRIX6
MAXICODE7
ITF8
EAN_139
EAN_810
PDF_41711
RSS_1412
RSS_EXPANDED13
UPC_A14
UPC_E15
UPC_EAN_EXTENSION16

CapacitorBarcodeScannerTypeHintALLOption

成员
ALL17

CapacitorBarcodeScannerCameraDirection

成员
BACK1
FRONT2

CapacitorBarcodeScannerScanOrientation

成员
PORTRAIT1
LANDSCAPE2
ADAPTIVE3

CapacitorBarcodeScannerAndroidScanningLibrary

成员
ZXING'zxing'
MLKIT'mlkit'