Barcode Scanner(バーコード・スキャナー)
Plugin 説明内容の英語表記部分について Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。
モバイル・アプリでカメラを使用し、QR コード、EAN-13、その他のバーコードをスキャン可能にします。
EAN-13 European Article Number: 商品識別コード/バーコード規格のひとつで、13 桁の「欧州商品番号」の意味。日本で最も普及している商品識別コードである「JAN コード」と同等のもの。《Wikipedia》
This plugin requires a Rust version of at least 1.77.2
| Platform | Level | Notes |
|---|---|---|
| windows | | |
| linux | | |
| macos | | |
| android | ||
| ios |
はじめに、「Barcode Scanner(バーコード・スキャナー)」プラグインをインストールしてください。
自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:
npm run tauri add barcode-scanneryarn run tauri add barcode-scannerpnpm tauri add barcode-scannerdeno task tauri add barcode-scannerbun tauri add barcode-scannercargo tauri add barcode-scanner-
src-tauriフォルダで次のコマンドを実行して、Cargo.toml内のプロジェクトの依存関係にこのプラグインを追加します:cargo add tauri-plugin-barcode-scanner --target 'cfg(any(target_os = "android", target_os = "ios"))' -
追加したプラグインを初期化するために
lib.rsを修正します:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().setup(|app| {#[cfg(mobile)]app.handle().plugin(tauri_plugin_barcode_scanner::init());Ok(())}).run(tauri::generate_context!()).expect("error while running tauri application");} -
お好みの JavaScript パッケージ・マネージャーを使用して、「JavaScript Guest」バインディングをインストールします:
npm install @tauri-apps/plugin-barcode-scanneryarn add @tauri-apps/plugin-barcode-scannerpnpm add @tauri-apps/plugin-barcode-scannerdeno add npm:@tauri-apps/plugin-barcode-scannerbun add @tauri-apps/plugin-barcode-scanner
iOS では、「Barcode Scanner」プラグインに、あなたのアプリがカメラを使用する理由を説明する NSCameraUsageDescription 情報プロパティ・リストの値が必要です。
src-tauri/Info.ios.plist ファイルには、以下のスニペット(内容)を追加してください。
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"> <dict> <key>NSCameraUsageDescription</key> <string>Read QR codes</string> </dict></plist>「Barcode Scanner」プラグインは JavaScript で利用できます。
import { scan, Format } from '@tauri-apps/plugin-barcode-scanner';// `"withGlobalTauri": true` を使用する場合は、// const { scan, Format } = window.__TAURI__.barcodeScanner; を使用できます;
// `windowed: true` は、カメラ用に別のビューを開くのではなく、// 実際には Webview を透明に設定します// 要素の透明化により下にあるものが表示されるように、ユーザーインターフェースを設定しておいてくださいscan({ windowed: true, formats: [Format.QRCode] });デフォルトでは、潜在的に危険なプラグイン・コマンドとそのスコープ(有効範囲)はすべてブロックされており、アクセスできません。これらを有効にするには、capabilities 設定でアクセス権限を変更する必要があります。
詳細については「セキュリティ・レベル Capabilities」の章を参照してください。また、プラグインのアクセス権限を設定するには「プライグン・アクセス権の使用」の章のステップ・バイ・ステップ・ガイドを参照してください。
{ "$schema": "../gen/schemas/mobile-schema.json", "identifier": "mobile-capability", "windows": ["main"], "platforms": ["iOS", "android"], "permissions": ["barcode-scanner:allow-scan", "barcode-scanner:allow-cancel"]}Default Permission
This permission set configures which barcode scanning features are by default exposed.
Granted Permissions
It allows all barcode related features.
This default permission set includes the following:
allow-cancelallow-check-permissionsallow-open-app-settingsallow-request-permissionsallow-scanallow-vibrate
Permission Table
| Identifier | Description |
|---|---|
|
|
Enables the cancel command without any pre-configured scope. |
|
|
Denies the cancel command without any pre-configured scope. |
|
|
Enables the check_permissions command without any pre-configured scope. |
|
|
Denies the check_permissions command without any pre-configured scope. |
|
|
Enables the open_app_settings command without any pre-configured scope. |
|
|
Denies the open_app_settings command without any pre-configured scope. |
|
|
Enables the request_permissions command without any pre-configured scope. |
|
|
Denies the request_permissions command without any pre-configured scope. |
|
|
Enables the scan command without any pre-configured scope. |
|
|
Denies the scan command without any pre-configured scope. |
|
|
Enables the vibrate command without any pre-configured scope. |
|
|
Denies the vibrate command without any pre-configured scope. |
【※ この日本語版は、「Jul 1, 2025 英語版」に基づいています】
© 2025 Tauri Contributors. CC-BY / MIT