{"_id":"@bytetrade/barcode-scanner","_rev":"6-8331375c1e9b7446276c738a4019c225","name":"@bytetrade/barcode-scanner","dist-tags":{"latest":"7.0.1"},"versions":{"6.0.1":{"name":"@bytetrade/barcode-scanner","version":"6.0.1","keywords":["capacitor","plugin","native"],"author":{"name":"tafelnl"},"license":"MIT","_id":"@bytetrade/barcode-scanner@6.0.1","maintainers":[{"name":"luz33c","email":"33cluz@gmail.com"},{"name":"huaiyuanzhao","email":"zhaohuaiyuan@bytetrade.io"},{"name":"yyh_yongheng","email":"yangyongheng@bytetrade.io"},{"name":"pengpeng1985","email":"pengpeng@bytetrade.io"}],"homepage":"https://github.com/capacitor-community/barcode-scanner#readme","bugs":{"url":"https://github.com/capacitor-community/barcode-scanner/issues"},"dist":{"shasum":"f2f1bd10962bd78f8ac5d93c66c674bad90d4f2f","tarball":"https://registry.npmjs.org/@bytetrade/barcode-scanner/-/barcode-scanner-6.0.1.tgz","fileCount":28,"integrity":"sha512-+W4jUKmFgYgR2S44W9iETvuHxU/j1IqHjZHvJMVXudZ6YHQID3+qzQw520YLPP7QaRhz/m9U8P1FFGh9J1A/nw==","signatures":[{"sig":"MEYCIQDMVnn0OUGZ61D5HUiiC5WtB3RvZ7fAjgtLR4Clvc4qCAIhAK3s9XFBr2qiqeNi3jz+T9wm0sZ8Tt3dvBb7f5ewV+J9","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":176394},"main":"dist/plugin.cjs.js","types":"dist/esm/index.d.ts","unpkg":"dist/plugin.js","module":"dist/esm/index.js","gitHead":"ec289b59d0eaa46bc9afa1ed3e43f44733798913","scripts":{"lint":"npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint","build":"npm run clean && tsc && rollup -c rollup.config.js --bundleConfigAsCjs","clean":"rimraf ./dist","watch":"tsc --watch","docgen":"docgen --api BarcodeScannerPlugin --output-readme API_REFERENCE.md","eslint":"eslint . --ext ts","verify":"npm run verify:ios && npm run verify:android && npm run verify:web","prettier":"prettier \"**/*.{css,html,ts,js,java}\"","swiftlint":"node-swiftlint","verify:ios":"cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination \"platform=iOS Simulator,name=iPhone 12\" && cd ..","verify:web":"npm run build","prepublishOnly":"npm run build","verify:android":"cd android && ./gradlew clean build test && cd .."},"_npmUser":{"name":"huaiyuanzhao","email":"zhaohuaiyuan@bytetrade.io"},"prettier":"@ionic/prettier-config","capacitor":{"ios":{"src":"ios"},"android":{"src":"android"}},"swiftlint":"@ionic/swiftlint-config","repository":{"url":"git+https://github.com/Above-Os/barcode-scanner.git","type":"git"},"_npmVersion":"8.19.4","description":"A fast and efficient (QR) barcode scanner for Capacitor","directories":{"example":"examples"},"_nodeVersion":"16.20.1","dependencies":{"@zxing/browser":"^0.1.3","@zxing/library":"^0.20.0"},"eslintConfig":{"extends":"@ionic/eslint-config/recommended","ignorePatterns":["dist/**/*"]},"_hasShrinkwrap":false,"devDependencies":{"husky":"^8.0.3","eslint":"^8.40.0","rimraf":"^5.0.0","rollup":"^3.21.5","prettier":"~2.8.8","swiftlint":"^1.0.2","typescript":"~5.0.4","pretty-quick":"^3.1.3","@capacitor/ios":"^6.1.0","@capacitor/core":"^6.1.0","@capacitor/docgen":"0.2.1","@capacitor/android":"^6.1.0","@ionic/eslint-config":"^0.3.0","prettier-plugin-java":"~2.1.0","@ionic/prettier-config":"^3.0.0","@ionic/swiftlint-config":"^1.1.2"},"peerDependencies":{"@capacitor/core":"^6.1.0"},"_npmOperationalInternal":{"tmp":"tmp/barcode-scanner_6.0.1_1721101849826_0.7088928017479648","host":"s3://npm-registry-packages"}},"6.0.2":{"name":"@bytetrade/barcode-scanner","version":"6.0.2","keywords":["capacitor","plugin","native"],"author":{"name":"tafelnl"},"license":"MIT","_id":"@bytetrade/barcode-scanner@6.0.2","maintainers":[{"name":"luz33c","email":"33cluz@gmail.com"},{"name":"huaiyuanzhao","email":"zhaohuaiyuan@bytetrade.io"},{"name":"yyh_yongheng","email":"yangyongheng@bytetrade.io"},{"name":"pengpeng1985","email":"pengpeng@bytetrade.io"}],"homepage":"https://github.com/capacitor-community/barcode-scanner#readme","bugs":{"url":"https://github.com/capacitor-community/barcode-scanner/issues"},"dist":{"shasum":"93254825cd3fdb173230360ba7a9ede4aa06b5aa","tarball":"https://registry.npmjs.org/@bytetrade/barcode-scanner/-/barcode-scanner-6.0.2.tgz","fileCount":28,"integrity":"sha512-F3iLnCDSa0W07e6GK4ZUAPvUv5OGNPsc4b7H8AirHbwTRw5ItztCznMxmWUlMGUY679HbXMdk+7suW+V8vAJHg==","signatures":[{"sig":"MEUCIGSWXBBHDWdz5Cyv6Rw1NVKzBBoJD+9iVM28bqVi1wIwAiEA7kVeuF6tfiZgpV9gpSOQGMKDTacJ9pRS1Um/1JbBwYY=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":176376},"main":"dist/plugin.cjs.js","types":"dist/esm/index.d.ts","unpkg":"dist/plugin.js","module":"dist/esm/index.js","gitHead":"ec289b59d0eaa46bc9afa1ed3e43f44733798913","scripts":{"lint":"npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint","build":"npm run clean && tsc && rollup -c rollup.config.js --bundleConfigAsCjs","clean":"rimraf ./dist","watch":"tsc --watch","docgen":"docgen --api BarcodeScannerPlugin --output-readme API_REFERENCE.md","eslint":"eslint . --ext ts","verify":"npm run verify:ios && npm run verify:android && npm run verify:web","prettier":"prettier \"**/*.{css,html,ts,js,java}\"","swiftlint":"node-swiftlint","verify:ios":"cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination \"platform=iOS Simulator,name=iPhone 12\" && cd ..","verify:web":"npm run build","prepublishOnly":"npm run build","verify:android":"cd android && ./gradlew clean build test && cd .."},"_npmUser":{"name":"huaiyuanzhao","email":"zhaohuaiyuan@bytetrade.io"},"prettier":"@ionic/prettier-config","capacitor":{"ios":{"src":"ios"},"android":{"src":"android"}},"swiftlint":"@ionic/swiftlint-config","repository":{"url":"git+https://github.com/Above-Os/barcode-scanner.git","type":"git"},"_npmVersion":"8.19.4","description":"A fast and efficient (QR) barcode scanner for Capacitor","directories":{"example":"examples"},"_nodeVersion":"16.20.1","dependencies":{"@zxing/browser":"^0.1.3","@zxing/library":"^0.20.0"},"eslintConfig":{"extends":"@ionic/eslint-config/recommended","ignorePatterns":["dist/**/*"]},"_hasShrinkwrap":false,"devDependencies":{"husky":"^8.0.3","eslint":"^8.40.0","rimraf":"^5.0.0","rollup":"^3.21.5","prettier":"~2.8.8","swiftlint":"^1.0.2","typescript":"~5.0.4","pretty-quick":"^3.1.3","@capacitor/ios":"^6.1.0","@capacitor/core":"^6.1.0","@capacitor/docgen":"0.2.1","@capacitor/android":"^6.1.0","@ionic/eslint-config":"^0.3.0","prettier-plugin-java":"~2.1.0","@ionic/prettier-config":"^3.0.0","@ionic/swiftlint-config":"^1.1.2"},"peerDependencies":{"@capacitor/core":"^6.1.0"},"_npmOperationalInternal":{"tmp":"tmp/barcode-scanner_6.0.2_1721102756861_0.8160216595455103","host":"s3://npm-registry-packages"}},"7.0.1":{"name":"@bytetrade/barcode-scanner","version":"7.0.1","keywords":["capacitor","plugin","native"],"author":{"name":"tafelnl"},"license":"MIT","_id":"@bytetrade/barcode-scanner@7.0.1","maintainers":[{"name":"pengpeng1985","email":"pengpeng@bytetrade.io"},{"name":"yyh_yongheng","email":"yangyongheng@bytetrade.io"},{"name":"huaiyuanzhao","email":"zhaohuaiyuan@bytetrade.io"},{"name":"icebergtsn","email":"zhangyuhang@bytetrade.io"},{"name":"luz33c","email":"33cluz@gmail.com"}],"homepage":"https://github.com/capacitor-community/barcode-scanner#readme","bugs":{"url":"https://github.com/capacitor-community/barcode-scanner/issues"},"dist":{"shasum":"4412a82f7a8d5dd6618b53ff390e2e4a4219b004","tarball":"https://registry.npmjs.org/@bytetrade/barcode-scanner/-/barcode-scanner-7.0.1.tgz","fileCount":28,"integrity":"sha512-5e5nl8Hty9bcTJRhujrsVYh4ReRT4Razeg/m0QjtsX4l3g5mQ4/0WAQlxqO8VcbiCaJkxmZ2Jm/13Rn9MPADhQ==","signatures":[{"sig":"MEUCIQCprM55Dauf7/PhVR4Utdta3XiwPMOxlvZL120oqhOGAgIgKRP95/kv05eIA5Ut7TdX+TYA2mG7BxnC8EGXco8E8LQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":175388},"main":"dist/plugin.cjs.js","types":"dist/esm/index.d.ts","unpkg":"dist/plugin.js","module":"dist/esm/index.js","gitHead":"ac74e30ea3571cd540e53cea7ce15a3114b950f2","scripts":{"lint":"npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint","build":"npm run clean && tsc && rollup -c rollup.config.mjs --bundleConfigAsCjs","clean":"rimraf ./dist","watch":"tsc --watch","docgen":"docgen --api BarcodeScannerPlugin --output-readme API_REFERENCE.md","eslint":"eslint . --ext ts","verify":"npm run verify:ios && npm run verify:android && npm run verify:web","prettier":"prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java","swiftlint":"node-swiftlint","verify:ios":"cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination \"platform=iOS Simulator,name=iPhone 12\" && cd ..","verify:web":"npm run build","prepublishOnly":"npm run build","verify:android":"cd android && ./gradlew clean build test && cd .."},"_npmUser":{"name":"icebergtsn","email":"zhangyuhang@bytetrade.io"},"prettier":"@ionic/prettier-config","capacitor":{"ios":{"src":"ios"},"android":{"src":"android"}},"swiftlint":"@ionic/swiftlint-config","repository":{"url":"git+https://github.com/Above-Os/barcode-scanner.git","type":"git"},"_npmVersion":"10.8.2","description":"A fast and efficient (QR) barcode scanner for Capacitor","directories":{"example":"examples"},"_nodeVersion":"20.19.4","dependencies":{"@zxing/browser":"^0.1.3","@zxing/library":"^0.20.0"},"eslintConfig":{"extends":"@ionic/eslint-config/recommended","ignorePatterns":["dist/**/*"]},"_hasShrinkwrap":false,"devDependencies":{"husky":"^8.0.3","eslint":"^8.57.0","rimraf":"^6.0.1","rollup":"^4.30.1","prettier":"^3.4.2","swiftlint":"^2.0.0","typescript":"~5.0.4","pretty-quick":"^3.1.3","@capacitor/ios":"^7.4.2","@capacitor/core":"^7.4.2","@capacitor/docgen":"^0.3.0","@capacitor/android":"^7.4.2","@ionic/eslint-config":"^0.4.0","prettier-plugin-java":"^2.6.6","@ionic/prettier-config":"^4.0.0","@ionic/swiftlint-config":"^2.0.0"},"peerDependencies":{"@capacitor/core":"^7.4.2"},"_npmOperationalInternal":{"tmp":"tmp/barcode-scanner_7.0.1_1755074400598_0.3614958521123144","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2024-07-16T03:50:49.731Z","modified":"2026-08-21T13:30:30.127Z","6.0.1":"2024-07-16T03:50:50.044Z","6.0.2":"2024-07-16T04:05:57.039Z","7.0.1":"2025-08-13T08:40:00.818Z"},"bugs":{"url":"https://github.com/capacitor-community/barcode-scanner/issues"},"author":{"name":"tafelnl"},"license":"MIT","homepage":"https://github.com/capacitor-community/barcode-scanner#readme","keywords":["capacitor","plugin","native"],"repository":{"url":"git+https://github.com/Above-Os/barcode-scanner.git","type":"git"},"description":"A fast and efficient (QR) barcode scanner for Capacitor","maintainers":[{"email":"pengpeng@bytetrade.io","name":"pengpeng1985"},{"email":"yangyongheng@bytetrade.io","name":"yyh_yongheng"},{"email":"zhangyuhang@bytetrade.io","name":"icebergtsn"},{"email":"33cluz@gmail.com","name":"luz33c"},{"email":"guojianmin@bytetrade.io","name":"guojianmin_123"}],"readme":"# DEPRECATED\n\nThis package is deprecated in favor of [`@capacitor-mlkit/barcode-scanning`](https://github.com/capawesome-team/capacitor-mlkit/tree/main/packages/barcode-scanning).\n`@capacitor-mlkit/barcode-scanning` has multiple features that are missing in this project, especially a prebuilt UI. \nNot having an out of the box solution was confusing for most users and caused a lot of issues.\nAdditionally, v5 of this plugin intended to switch to `ml-kit` and this brings additional problems if you want to use multiple parts of `ml-kit` in the same application, which is solved by `@capacitor-mlkit/barcode-scanning` as well.\n\n\n<p align=\"center\"><br><img src=\"https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png\" width=\"128\" height=\"128\" /></p>\n<h3 align=\"center\">Barcode Scanner</h3>\n<p align=\"center\"><strong><code>@capacitor-community/barcode-scanner</code></strong></p>\n<p align=\"center\">\n  A fast and efficient (QR) barcode scanner for Capacitor.\n</p>\n\n<p align=\"center\">\n  <img src=\"https://img.shields.io/maintenance/no/2023?style=flat-square\" />\n  <a href=\"https://www.npmjs.com/package/@capacitor-community/barcode-scanner\"><img src=\"https://img.shields.io/npm/l/@capacitor-community/barcode-scanner?style=flat-square\" /></a>\n<br>\n  <a href=\"https://www.npmjs.com/package/@capacitor-community/barcode-scanner\"><img src=\"https://img.shields.io/npm/dw/@capacitor-community/barcode-scanner?style=flat-square\" /></a>\n  <a href=\"https://www.npmjs.com/package/@capacitor-community/barcode-scanner\"><img src=\"https://img.shields.io/npm/v/@capacitor-community/barcode-scanner?style=flat-square\" /></a>\n<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->\n<a href=\"#contributors-\"><img src=\"https://img.shields.io/badge/all%20contributors-1-orange?style=flat-square\" /></a>\n<!-- ALL-CONTRIBUTORS-BADGE:END -->\n</p>\n\n## Table of Contents\n\n- [Maintainers](#maintainers)\n- [About](#about)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Troubleshooting](#troubleshooting)\n\n## Maintainers\n\n| Maintainer | GitHub                                | Active |\n| ---------- | ------------------------------------- | ------ |\n| thegnuu    | [thegnuu](https://github.com/thegnuu) | no     |\n| tafelnl    | [tafelnl](https://github.com/tafelnl) | no     |\n\n## About\n\n### Supported barcodes\n\nOn **iOS** this library makes use of Apple's own `AVFoundation`. This means **[this list of barcodes](https://developer.apple.com/documentation/avfoundation/avmetadatamachinereadablecodeobject/machine-readable_object_types)** should be supported.\n\nOn **Android** this library uses [`zxing-android-embedded`](https://github.com/journeyapps/zxing-android-embedded) which uses [`zxing`](https://github.com/zxing/zxing) under the hood. That means **[this list of barcodes](https://github.com/zxing/zxing/#supported-formats)** is supported.\n\nOn **Web** this library uses [`zxing/browser`](https://github.com/zxing-js/browser). That means **[this list of barcodes](https://github.com/zxing/zxing/#supported-formats)** is supported. The web implementation is currently in development, there might be issues and not all features are currently supported!\n\n### Note on supported Capacitor versions\n\n`v7.x` supports Capacitor `v7.x`\n\n`v6.x` supports Capacitor `v6.x`\n\n`v5.x.x-beta.x` pre-release based on ML-Kit that supports Capacitor `v5.x`\n\n`v4.x` supports Capacitor `v5.x`\n\n`v3.x` supports Capacitor `v4.x`\n\n`v2.x` supports Capacitor `v3.x`\n\n`v1.x` supports Capacitor `v2.x`\n\nAll releases of this package can be found on [npm](https://www.npmjs.com/package/@capacitor-community/barcode-scanner?activeTab=versions) and on [GitHub Releases](https://github.com/capacitor-community/barcode-scanner/releases)\n\n## Installation\n\n```bash\nnpm install @capacitor-community/barcode-scanner\nnpx cap sync\n```\n\n### iOS\n\nFor iOS you need to set a usage description in your info.plist file.\n\nThis can be done by either adding it to the Source Code directly or by using Xcode Property List inspector.\n\n**Adding it to the source code directly**\n\n1. Open up the Info.plist (in Xcode right-click > Open As > Source Code)\n2. With `<dict></dict>` change the following\n\n```diff\n<dict>\n+  <key>NSCameraUsageDescription</key>\n+  <string>To be able to scan barcodes</string>\n</dict>\n```\n\n_NOTE:_ \"To be able to scan barcodes\" can be substituted for anything you like.\n\n**Adding it by using Xcode Property List inspector**\n\n1. Open up the Info.plist **in Xcode** (right-click > Open As > Property List)\n2. Next to \"Information Property List\" click on the tiny `+` button.\n3. Under `key`, type \"Privacy - Camera Usage Description\"\n4. Under `value`, type \"To be able to scan barcodes\"\n\n_NOTE:_ \"To be able to scan barcodes\" can be substituted for anything you like.\n\nMore info here: https://developer.apple.com/documentation/bundleresources/information_property_list/nscamerausagedescription\n\n### Android\n\nWithin your `AndroidManifest.xml` file, change the following:\n\n```diff\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest\n  xmlns:android=\"http://schemas.android.com/apk/res/android\"\n+  xmlns:tools=\"http://schemas.android.com/tools\"\n  package=\"com.example\">\n\n  <application\n+    android:hardwareAccelerated=\"true\"\n  >\n  </application>\n\n+  <uses-permission android:name=\"android.permission.CAMERA\" />\n\n+  <uses-sdk tools:overrideLibrary=\"com.google.zxing.client.android\" />\n</manifest>\n```\n\n## Usage\n\nThe complete API reference can be found [here](./src/definitions.ts).\n\nScanning a (QR) barcode can be as simple as:\n\n```js\nimport { BarcodeScanner } from '@capacitor-community/barcode-scanner';\n\nconst startScan = async () => {\n  // Check camera permission\n  // This is just a simple example, check out the better checks below\n  await BarcodeScanner.checkPermission({ force: true });\n\n  // make background of WebView transparent\n  // note: if you are using ionic this might not be enough, check below\n  BarcodeScanner.hideBackground();\n\n  const result = await BarcodeScanner.startScan(); // start scanning and wait for a result\n\n  // if the result has content\n  if (result.hasContent) {\n    console.log(result.content); // log the raw scanned content\n  }\n};\n```\n\n### Opacity of the WebView\n\n`hideBackground()` will make the `<html>` element transparent by adding `background: 'transparent';` to the `style` attribute.\n\nIf you are using Ionic you need to set some css variables as well, check [**here**](#ionic-css-variables)\n\nIf you still cannot see the camera view, check [**here**](#the-scanner-view-does-not-show-up)\n\n### Stopping a scan\n\nAfter `startScan()` is resolved, the Scanner View will be automatically destroyed to save battery. But if you want to cancel the scan before `startScan()` is resolved (AKA no code has been recognized yet), you will have to call `stopScan()` manually. Example:\n\n```js\nimport { BarcodeScanner } from '@capacitor-community/barcode-scanner';\n\nconst stopScan = () => {\n  BarcodeScanner.showBackground();\n  BarcodeScanner.stopScan();\n};\n```\n\nIt is also important to think about cases where a users hits some sort of a back button (either hardware or software). It is advised to call `stopScan()` in these types of situations as well.\n\nIn Vue.js you could do something like this in a specific view where you use the scanner:\n\n```vue\n<script>\nimport { BarcodeScanner } from '@capacitor-community/barcode-scanner';\n\nexport default {\n  methods: {\n    stopScan() {\n      BarcodeScanner.showBackground();\n      BarcodeScanner.stopScan();\n    },\n  },\n\n  deactivated() {\n    this.stopScan();\n  },\n\n  beforeDestroy() {\n    this.stopScan();\n  },\n};\n</script>\n```\n\n### Preparing a scan\n\nTo boost performance and responsiveness (by just a bit), a `prepare()` method is available. If you know your script will call `startScan()` sometime very soon, you can call `prepare()` to make `startScan()` work even faster.\n\nFor example:\n\n```js\nimport { BarcodeScanner } from '@capacitor-community/barcode-scanner';\n\nconst prepare = () => {\n  BarcodeScanner.prepare();\n};\n\nconst startScan = async () => {\n  BarcodeScanner.hideBackground();\n  const result = await BarcodeScanner.startScan();\n  if (result.hasContent) {\n    console.log(result.content);\n  }\n};\n\nconst stopScan = () => {\n  BarcodeScanner.showBackground();\n  BarcodeScanner.stopScan();\n};\n\nconst askUser = () => {\n  prepare();\n\n  const c = confirm('Do you want to scan a barcode?');\n\n  if (c) {\n    startScan();\n  } else {\n    stopScan();\n  }\n};\n\naskUser();\n```\n\nThis is fully optional and would work the same as:\n\n```js\nimport { BarcodeScanner } from '@capacitor-community/barcode-scanner';\n\nconst startScan = async () => {\n  BarcodeScanner.hideBackground();\n  const result = await BarcodeScanner.startScan();\n  if (result.hasContent) {\n    console.log(result.content);\n  }\n};\n\nconst askUser = () => {\n  const c = confirm('Do you want to scan a barcode?');\n\n  if (c) {\n    startScan();\n  }\n};\n\naskUser();\n```\n\nThe latter will just appear a little slower to the user.\n\n### Permissions\n\nThis plugin does not automatically handle permissions. But the plugin _does_ have a utility method to check and request the permission. You will have to request the permission from JavaScript. A simple example follows:\n\n```js\nimport { BarcodeScanner } from '@capacitor-community/barcode-scanner';\n\nconst checkPermission = async () => {\n  // check or request permission\n  const status = await BarcodeScanner.checkPermission({ force: true });\n\n  if (status.granted) {\n    // the user granted permission\n    return true;\n  }\n\n  return false;\n};\n```\n\nA more detailed and more UX-optimized example:\n\n```js\nimport { BarcodeScanner } from '@capacitor-community/barcode-scanner';\n\nconst didUserGrantPermission = async () => {\n  // check if user already granted permission\n  const status = await BarcodeScanner.checkPermission({ force: false });\n\n  if (status.granted) {\n    // user granted permission\n    return true;\n  }\n\n  if (status.denied) {\n    // user denied permission\n    return false;\n  }\n\n  if (status.asked) {\n    // system requested the user for permission during this call\n    // only possible when force set to true\n  }\n\n  if (status.neverAsked) {\n    // user has not been requested this permission before\n    // it is advised to show the user some sort of prompt\n    // this way you will not waste your only chance to ask for the permission\n    const c = confirm('We need your permission to use your camera to be able to scan barcodes');\n    if (!c) {\n      return false;\n    }\n  }\n\n  if (status.restricted || status.unknown) {\n    // ios only\n    // probably means the permission has been denied\n    return false;\n  }\n\n  // user has not denied permission\n  // but the user also has not yet granted the permission\n  // so request it\n  const statusRequest = await BarcodeScanner.checkPermission({ force: true });\n\n  if (statusRequest.asked) {\n    // system requested the user for permission during this call\n    // only possible when force set to true\n  }\n\n  if (statusRequest.granted) {\n    // the user did grant the permission now\n    return true;\n  }\n\n  // user did not grant the permission, so he must have declined the request\n  return false;\n};\n\ndidUserGrantPermission();\n```\n\nIf a user denied the permission for good, `status.denied` will be set to true. On Android this will happen only when the user checks the box `never ask again`. To get the permission anyway you will have to redirect the user to the settings of the app. This can be done simply be doing the following:\n\n```js\nimport { BarcodeScanner } from '@capacitor-community/barcode-scanner';\n\nconst checkPermission = async () => {\n  const status = await BarcodeScanner.checkPermission();\n\n  if (status.denied) {\n    // the user denied permission for good\n    // redirect user to app settings if they want to grant it anyway\n    const c = confirm('If you want to grant permission for using your camera, enable it in the app settings.');\n    if (c) {\n      BarcodeScanner.openAppSettings();\n    }\n  }\n};\n```\n\n### Target only specific barcodes\n\nYou can setup the scanner to only recognize specific types of barcodes like this:\n\n```ts\nimport { BarcodeScanner, SupportedFormat } from '@capacitor-community/barcode-scanner';\n\nBarcodeScanner.startScan({ targetedFormats: [SupportedFormat.QR_CODE] }); // this will now only target QR-codes\n```\n\nIf `targetedFormats` is _not specified_ or _left empty_, _all types_ of barcodes will be targeted.\n\nTargeting only specific types can have the following benefits:\n\n- Improved performance (since the decoder only has to look for the specified barcodes)\n- Improved User Experience (since scanning a barcode that is not supported by your case, will not work)\n\nThe following types are supported:\n\n<table>\n  <thead>\n    <tr>\n      <th>Category</th>\n      <th>Type</th>\n      <th>Android</th>\n      <th>iOS</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <td rowspan=\"6\">1D Product</td>\n    </tr>\n    <tr>\n      <td>UPC_A</td>\n      <td>✔</td>\n      <td>✔**</td>\n    </tr>\n    <tr>\n      <td>UPC_E</td>\n      <td>✔</td>\n      <td>✔</td>\n    </tr>\n    <tr>\n      <td>UPC_EAN_EXTENSION</td>\n      <td>✔</td>\n      <td>✖</td>\n    </tr>\n    <tr>\n      <td>EAN_8</td>\n      <td>✔</td>\n      <td>✔</td>\n    </tr>\n    <tr>\n      <td>EAN_13</td>\n      <td>✔</td>\n      <td>✔</td>\n    </tr>\n    <tr>\n      <td rowspan=\"8\">1D Industrial</td>\n    </tr>\n    <tr>\n      <td>CODE_39</td>\n      <td>✔</td>\n      <td>✔</td>\n    </tr>\n    <tr>\n      <td>CODE_39_MOD_43</td>\n      <td>✖</td>\n      <td>✔</td>\n    </tr>\n    <tr>\n      <td>CODE_93</td>\n      <td>✔</td>\n      <td>✔</td>\n    </tr>\n    <tr>\n      <td>CODE_128</td>\n      <td>✔</td>\n      <td>✔</td>\n    </tr>\n    <tr>\n      <td>CODABAR</td>\n      <td>✔</td>\n      <td>✖</td>\n    </tr>\n    <tr>\n      <td>ITF</td>\n      <td>✔</td>\n      <td>✔</td>\n    </tr>\n    <tr>\n      <td>ITF_14</td>\n      <td>✖</td>\n      <td>✔</td>\n    </tr>\n    <tr>\n      <td rowspan=\"8\">2D</td>\n    </tr>\n    <tr>\n      <td>AZTEC</td>\n      <td>✔</td>\n      <td>✔</td>\n    </tr>\n    <tr>\n      <td>DATA_MATRIX</td>\n      <td>✔</td>\n      <td>✔</td>\n    </tr>\n    <tr>\n      <td>MAXICODE</td>\n      <td>✔</td>\n      <td>✖</td>\n    </tr>\n    <tr>\n      <td>PDF_417</td>\n      <td>✔</td>\n      <td>✔</td>\n    </tr>\n    <tr>\n      <td>QR_CODE</td>\n      <td>✔</td>\n      <td>✔</td>\n    </tr>\n    <tr>\n      <td>RSS_14</td>\n      <td>✔</td>\n      <td>✖</td>\n    </tr>\n    <tr>\n      <td>RSS_EXPANDED</td>\n      <td>✔</td>\n      <td>✖</td>\n    </tr>\n  </tbody>\n</table>\n\n\\*\\* `UPC_A` is supported on iOS, but according to the offical [Apple docs](https://developer.apple.com/documentation/avfoundation/avmetadataobject/objecttype/1618807-ean13) it is part of `EAN_13`. So you should specify `EAN_13` to be able to scan this. If you want to distinguish them from one another, you should manually do so after getting the result.\n\n## Troubleshooting\n\n### Ionic CSS variables\n\nIonic will add additional CSS variables which will prevent the scanner from showing up.\nTo fix this issue add the following snippet at the end of your global css.\n\n```css\nbody.scanner-active {\n  --background: transparent;\n  --ion-background-color: transparent;\n}\n```\n\nOnce this is done, you need to add this class to the body before using the scanner.\n\n```typescript\ndocument.querySelector('body').classList.add('scanner-active');\n```\n\nAfter your done with your scanning work, you can simply remove this class.\n\n```typescript\ndocument.querySelector('body').classList.remove('scanner-active');\n```\n\n### I have a `Error: Plugin BarcodeScanner does not respond to method call` error message on iOS\n\nIn Xcode click on `Product` > `Clean Build Folder` and try to build again.\n\n### I have a `Cannot resolve symbol BarcodeScanner` error message in Android Studio\n\nIn Android Studio click `File` > `Sync Project with Gradle Files` and try to build again.\n\n### The scanner view does not show up\n\nIf you cannot see the scanner in your viewport, please follow these steps:\n\n1. Check if camera permissions are granted properly\n2. Check if the scanner element does appear inside the DOM, somewhere within the `body` tag\n   - [It's not there](#i-do-not-find-the-scanner-in-the-dom)\n3. Check if some DOM elements are rendered on top of the scanner\n   - Search which element is causing the issue [#7](https://github.com/capacitor-community/barcode-scanner/issues/7#issuecomment-744441148)\n   - Play with javascript [#26](https://github.com/capacitor-community/barcode-scanner/issues/26)\n\n### I do not find the scanner in the DOM\n\nThis should appear in the DOM when running the `BarcodeScanner.startScan()` method.\n\n```html\n<body>\n  <!-- ... -->\n  <div style=\"position: absolute; left: 0px; top: -2px; height: 1px; overflow: hidden; visibility: hidden; width: 1px;\">\n    <span\n      style=\"position: absolute; font-size: 300px; width: auto; height: auto; margin: 0px; padding: 0px; font-family: Roboto, Arial, sans-serif;\"\n      >BESbswy</span\n    >\n  </div>\n  <!-- ... -->\n</body>\n```\n\nIf it does not, it may be a bug due to the component being loaded to deep inside the DOM tree.\nYou can try to see if the plugin is working properly by adding the following in your `app.component.ts` file.\n\n```typescript\nBarcodeScanner.hideBackground();\nconst result = await BarcodeScanner.startScan();\n```\n\n#### It doesn't appear\n\nIt could mean that you have missed a step by the [plugin configuration](#installation).\n\n#### I did the configuration correctly\n\nplease [open an issue](https://github.com/capacitor-community/barcode-scanner/issues/new/choose)\n\n## TODO\n\nA non-exhaustive list of todos:\n\n- Support for switching between cameras\n- Support for web\n","readmeFilename":"README.md"}