コンテンツにスキップ
Tauri

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-scanner

iOS では、「Barcode Scanner」プラグインに、あなたのアプリがカメラを使用する理由を説明する NSCameraUsageDescription 情報プロパティ・リストの値が必要です。

src-tauri/Info.ios.plist ファイルには、以下のスニペット(内容)を追加してください。

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」の章を参照してください。また、プラグインのアクセス権限を設定するには「プライグン・アクセス権の使用」の章のステップ・バイ・ステップ・ガイドを参照してください。

src-tauri/capabilities/mobile.json
{
"$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-cancel
  • allow-check-permissions
  • allow-open-app-settings
  • allow-request-permissions
  • allow-scan
  • allow-vibrate

Permission Table

Identifier Description

barcode-scanner:allow-cancel

Enables the cancel command without any pre-configured scope.

barcode-scanner:deny-cancel

Denies the cancel command without any pre-configured scope.

barcode-scanner:allow-check-permissions

Enables the check_permissions command without any pre-configured scope.

barcode-scanner:deny-check-permissions

Denies the check_permissions command without any pre-configured scope.

barcode-scanner:allow-open-app-settings

Enables the open_app_settings command without any pre-configured scope.

barcode-scanner:deny-open-app-settings

Denies the open_app_settings command without any pre-configured scope.

barcode-scanner:allow-request-permissions

Enables the request_permissions command without any pre-configured scope.

barcode-scanner:deny-request-permissions

Denies the request_permissions command without any pre-configured scope.

barcode-scanner:allow-scan

Enables the scan command without any pre-configured scope.

barcode-scanner:deny-scan

Denies the scan command without any pre-configured scope.

barcode-scanner:allow-vibrate

Enables the vibrate command without any pre-configured scope.

barcode-scanner:deny-vibrate

Denies the vibrate command without any pre-configured scope.

【※ この日本語版は、「Jul 1, 2025 英語版」に基づいています】


© 2025 Tauri Contributors. CC-BY / MIT