# PhoneGap BarcodeScanner

{% hint style="danger" %}
非推奨プラグイン (Cordova 9.0 以降)
{% endhint %}

{% hint style="info" %}

* サードパーティー製 Cordova プラグインを確認する場合は、カスタムビルドデバッガー ( [Android 版](/products_guide/debugger/installation/debugger_android.md#kasutamubirudo-monaca-debaggnobirudotoinsutru)または [iOS 版](/products_guide/debugger/installation/debugger_ios.md#kasutamubirudo-monaca-debaggnobirudo) ) を作成する必要があります。
* Cordova 7.1 用 Android カスタムビルドデバッガーで使用する場合は、config.xml に次の設定をしてビルドする必要があります。\
  \
  &#x20;\<preference name="monaca:ANDROID\_DEBUGGER\_APPCOMPAT\_VERSION" value="27.+" /><br>
* Cordova 7.1 で提供している MonacaBackend プラグインと組み合わせる場合は、プラグイン設定画面の「インストールパラメータ」に下記の設定が必要になります。\
  \
  &#x20;ANDROID\_SUPPORT\_V4\_VERSION=26.+
  {% endhint %}

## iOS 特有の動作

iOS 10以降、プライバシーに関連するデータにアクセスする場合は、 `info.plist` に使用の説明を設定することが必須になります。アクセスを許可するようにシステムに指示すると、この使用の説明はアクセス許可ダイアログボックスの一部として表示されますが、使用の説明を入力しない場合は、ダイアログが表示される前にアプリが強制終了します。また、Apple は個人データにアクセスするアプリをリジェクトしますが、使用の説明は提供していません。

このプラグインでは、次の使用の説明が必要になります。

* `NSCameraUsageDescription` には、アプリがユーザーのカメラにアクセスする理由を記述します。

この設定を `info.plist` に追加するには、`config.xml` ファイルの `<edit-config>` タグに以下のように設定します。

```markup
<edit-config target="NSCameraUsageDescription" file="*-Info.plist" mode="merge">
    <string>To scan barcodes</string>
</edit-config>
```

## プラグインの追加方法 ( Monaca 上での処理 )

1. Monaca クラウド IDE か&#x3089;**`設定 → Cordova プラグインの管理`** を選択します。
2. *利用可能なプラグイン* 項目の `Phonegap BarcodeScanner` プラグインにカーソルを置き、 ボタンをクリックします。

![](/files/-MgOdw8Sh1VtTx70XOTi)

## PhoneGap BarcodeScanner プラグインのデモ

PhoneGap BarcodeScanner プラグインの使用例を、次に記します。

```javascript
<!DOCTYPE HTML>
<html>
<head>
  <title>PhoneGap BarcodeScanner Plugin DEMO</title>

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <meta http-equiv="Content-Security-Policy" content="default-src * data: gap: https://ssl.gstatic.com; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">
  <script src="components/loader.js"></script>
  <link rel="stylesheet" href="components/loader.css">
  <link rel="stylesheet" href="css/style.css">
  <script>
    function scanBarcode() {
      cordova.plugins.barcodeScanner.scan(
        function (result) {
          alert("We got a barcode\n" +
                "Result: " + result.text + "\n" +
                "Format: " + result.format + "\n" +
                "Cancelled: " + result.cancelled);
        },
        function (error) {
          alert("Scanning failed: " + error);
        },
        {
          preferFrontCamera : true, // iOS and Android
          showFlipCameraButton : true, // iOS and Android
          showTorchButton : true, // iOS and Android
          torchOn: true, // Android, launch with the torch switched on (if available)
          saveHistory: true, // Android, save scan history (default false)
          prompt : "Place a barcode inside the scan area", // Android
          resultDisplayDuration: 500, // Android, display scanned text for X ms. 0 suppresses it entirely, default 1500
          formats : "QR_CODE,PDF_417", // default: all but PDF_417 and RSS_EXPANDED
          orientation : "landscape", // Android only (portrait|landscape), default unset so it rotates with the device
          disableAnimations : true, // iOS
          disableSuccessBeep: false // iOS and Android
        }
      );
    }
  </script>
</head>
<body>
  <hr> BarcodeReader DEMO <hr><br>
  <input type="button" onClick ="scanBarcode()" value ="Scan" />
</body>
</html>
```

関連項目：

* [基本プラグイン](/reference/core-cordova-plugins.md)
* [サードパーティー製プラグイン](/reference/third_party_phonegap.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ja.docs.monaca.io/reference/third_party_phonegap/phonegap_plugin_barcodescanner.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
