{"id":165,"date":"2023-12-28T10:44:01","date_gmt":"2023-12-28T10:44:01","guid":{"rendered":"https:\/\/200oksolutionssandbox.co.uk\/blog\/?p=165"},"modified":"2024-07-09T07:42:39","modified_gmt":"2024-07-09T07:42:39","slug":"barcode-qr-code-scanner-react-native","status":"publish","type":"post","link":"https:\/\/200oksolutionssandbox.co.uk\/blog\/barcode-qr-code-scanner-react-native\/","title":{"rendered":"Barcode\/QR Code Scanner (React Native)"},"content":{"rendered":"\n<figure id=\"qr-barcode-scanner\" class=\"wp-block-video\"><video poster=\"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2023\/12\/Barcode_QR-Code-Scanner-with-React-Native-portrait-1.mp4\" src=\"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2024\/07\/Barcode_QR-Code-Scanner-with-React-Native-portrait.mp4\"><\/video><\/figure>\n\n\n\n<p><strong>What is a Barcode &amp; QR code?<\/strong><\/p>\n\n\n\n<p>A barcode holds information horizontally, while a QR code (Quick Response) holds information both vertically and horizontally.<\/p>\n\n\n\n<div style=\"height:14px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>To implement a barcode scanner in React Native, you&#8217;ll need <code>react-native-vision-camera<\/code> and <code>react-native-worklets-core<\/code>. These dependencies utilize MLKit Vision on Android and Apple Vision on iOS.<br><br>Install dependencies:<\/p>\n\n\n\n<p>command 1: <strong>npm install react-native-vision-camera@3.3.0<\/strong><\/p>\n\n\n\n<p>command 2: <strong>npm install react-native-worklets-core@0.2.2<\/strong><\/p>\n\n\n\n<div style=\"height:13px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Add the worklet plugin to your babel.config.js:<\/p>\n\n\n\n<pre class=\"wp-block-code has-silver-blue-background-color has-background\"><code>module.exports = {\n   plugins: &#91;\n        &#91;'react-native-worklets-core\/plugin']\n   ],\n}<\/code><\/pre>\n\n\n\n<p><strong>Configure Permissions<\/strong><\/p>\n\n\n\n<p><strong>Android<\/strong>: Add the following lines to your AndroidManifest.xml:<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-3d94d53e973cdcde5057132c068b62d1\"><code>&lt;uses-permission android:name=\"android.permission.CAMERA\" \/&gt;<\/code><\/pre>\n\n\n\n<p><strong>iOS:<\/strong> Add the following lines to your Info.plist:<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-11bd5d5f86e8ba1f0cf2435a73e75e37\"><code>&lt;key&gt;NSCameraUsageDescription&lt;\/key&gt;\n&lt;string&gt;$(PRODUCT_NAME) needs access to your Camera.&lt;\/string&gt;<\/code><\/pre>\n\n\n\n<div style=\"height:14px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Additional Android Setup:<\/strong><\/p>\n\n\n\n<p class=\"has-text-align-left\">Ensure your build.gradle includes the following configurations:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li> Set <strong>buildToolsVersion<\/strong> to 33.0.0 or higher<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li> Set <strong>compileSdkVersion<\/strong> to 33 or higher<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li> Set <strong>targetSdkVersion<\/strong> to 33 or higher<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li> Set <strong>minSdkVersio<\/strong>n to 26 or higher<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li> Set <strong>ndkVersion<\/strong> to &#8220;23.1.7779620&#8221; or higher<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Update the Gradle Build-Tools version<\/li>\n<\/ul>\n\n\n\n<p>In Android Make sure your Gradle Wrapper version is 7.5.1 or higher in gradle-wrapper.properties:<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-9b99ea71a13627078f2ea991b7bd0e95\"><code>distributionUrl=https\\:\/\/services.gradle.org\/distributions\/gradle-7.5.1-all.zip<\/code><\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Troubleshoot<\/strong> <\/p>\n\n\n\n<p>Use the <code>useCameraDevice<\/code> hook to access the camera:<\/p>\n\n\n\n<div style=\"height:16px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Get Device<\/strong><\/p>\n\n\n\n<p>By using <strong>useCameraDevice<\/strong> hook, by passing \u2018back\u2019 as a parameter we are able to get the device which is required by camera component.<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-9fddf11c792f37ecc42919dfc23c4466\"><code>const device = useCameraDevice('back');<\/code><\/pre>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Getting\/Requesting Permission<\/strong><\/p>\n\n\n\n<p>Use the useCameraPermission hook to request camera permissions:<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-6419d5ddfbe0073bce478ec3557c8c9a\"><code>const { hasPermission, requestPermission } = useCameraPermission();<\/code><\/pre>\n\n\n\n<p><strong>Frame Processors<\/strong>:<\/p>\n\n\n\n<p>Frame processors are functions that process frames the camera &#8220;sees&#8221;. Use them to call high-performance native functions for specific use cases:<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-471d887b9bebe0caf5fc177fee5c862f\"><code>const frameProcessor = useFrameProcessor((frame) =&gt; { \n      'worklet'\n      const objects = detectObjects(frame)\n      console.log(`Detected ${objects.length} objects.`) \n}, &#91;])<\/code><\/pre>\n\n\n\n<p><strong>CodeScanner<\/strong><\/p>\n\n\n\n<p>Use the useCodeScanner hook to detect codes in a camera stream:<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-silver-blue-background-color has-text-color has-background has-link-color wp-elements-d68419501de7aa0b221e5323abcf52e9\"><code>const codeScanner = useCodeScanner({ \n      codeTypes: &#91;'qr', 'ean-13'], \n      onCodeScanned: (codes) =&gt; { \n           console.log(`Scanned ${codes.length} codes!`) \n      } \n})<\/code><\/pre>\n\n\n\n<p><strong>Scanner Example<\/strong><\/p>\n\n\n\n<p>Refer to the demo app for a comprehensive example. Check out the sample barcode code-128 and QR code. <a data-type=\"link\" data-id=\"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2023\/12\/BarcodeQRScanCode.txt\" href=\"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2023\/12\/BarcodeQRScanCode.txt\" target=\"_blank\" rel=\"noreferrer noopener\">BarcodeQRScanCode<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<p class=\"has-text-align-left\"><strong>Barcode code-128<\/strong><\/p>\n\n\n\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" width=\"400\" height=\"100\" src=\"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2023\/12\/image-3.png\" alt=\"\" class=\"wp-image-169\" style=\"width:321px;height:auto\"\/><\/figure>\n\n\n\n<div style=\"height:29px;width:0px\" aria-hidden=\"true\" class=\"wp-block-spacer wp-container-content-7eea9941\"><\/div>\n<\/div>\n<\/div>\n\n\n\n<p> <strong>QR code<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1012\" height=\"1012\" src=\"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2023\/12\/image-2-1.png\" alt=\"\" class=\"wp-image-171\" style=\"width:159px;height:auto\"\/><\/figure>\n\n\n\n<p>Please check out the demo app for better understanding <a href=\"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2023\/12\/qrcode_scanner_recording-1.mp4\" data-type=\"link\" data-id=\"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2023\/12\/qrcode_scanner_recording-1.mp4\">qrcode_scanner_recording.mp4<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is a Barcode &amp; QR code? A barcode holds information horizontally, while a QR&hellip;<\/p>\n","protected":false},"author":1,"featured_media":174,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[18,16,13,17,14,19],"class_list":["post-165","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mobile","tag-barcode-scanner","tag-cross-platform","tag-hybrid","tag-qr-scanner","tag-react-native","tag-scanner"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Barcode\/QR Code Scanner (React Native)<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/200oksolutionssandbox.co.uk\/blog\/barcode-qr-code-scanner-react-native\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Barcode\/QR Code Scanner (React Native)\" \/>\n<meta property=\"og:description\" content=\"What is a Barcode &amp; QR code? A barcode holds information horizontally, while a QR&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/200oksolutionssandbox.co.uk\/blog\/barcode-qr-code-scanner-react-native\/\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/profile.php?id=61552217825863\" \/>\n<meta property=\"article:published_time\" content=\"2023-12-28T10:44:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-09T07:42:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2023\/12\/Untitled-design.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"BlogAdmin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"BlogAdmin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Barcode\/QR Code Scanner (React Native)","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/200oksolutionssandbox.co.uk\/blog\/barcode-qr-code-scanner-react-native\/","og_locale":"en_US","og_type":"article","og_title":"Barcode\/QR Code Scanner (React Native)","og_description":"What is a Barcode &amp; QR code? A barcode holds information horizontally, while a QR&hellip;","og_url":"https:\/\/200oksolutionssandbox.co.uk\/blog\/barcode-qr-code-scanner-react-native\/","article_publisher":"https:\/\/www.facebook.com\/profile.php?id=61552217825863","article_published_time":"2023-12-28T10:44:01+00:00","article_modified_time":"2024-07-09T07:42:39+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2023\/12\/Untitled-design.png","type":"image\/png"}],"author":"BlogAdmin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"BlogAdmin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/barcode-qr-code-scanner-react-native\/#article","isPartOf":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/barcode-qr-code-scanner-react-native\/"},"author":{"name":"BlogAdmin","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#\/schema\/person\/ea0b72006227b3403f5ad825b82ced43"},"headline":"Barcode\/QR Code Scanner (React Native)","datePublished":"2023-12-28T10:44:01+00:00","dateModified":"2024-07-09T07:42:39+00:00","mainEntityOfPage":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/barcode-qr-code-scanner-react-native\/"},"wordCount":265,"commentCount":0,"publisher":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#organization"},"image":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/barcode-qr-code-scanner-react-native\/#primaryimage"},"thumbnailUrl":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2023\/12\/Untitled-design.png","keywords":["barcode scanner","cross platform","hybrid","qr scanner","react native","scanner"],"articleSection":["Mobile"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/200oksolutionssandbox.co.uk\/blog\/barcode-qr-code-scanner-react-native\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/barcode-qr-code-scanner-react-native\/","url":"https:\/\/200oksolutionssandbox.co.uk\/blog\/barcode-qr-code-scanner-react-native\/","name":"Barcode\/QR Code Scanner (React Native)","isPartOf":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/barcode-qr-code-scanner-react-native\/#primaryimage"},"image":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/barcode-qr-code-scanner-react-native\/#primaryimage"},"thumbnailUrl":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2023\/12\/Untitled-design.png","datePublished":"2023-12-28T10:44:01+00:00","dateModified":"2024-07-09T07:42:39+00:00","breadcrumb":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/barcode-qr-code-scanner-react-native\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/200oksolutionssandbox.co.uk\/blog\/barcode-qr-code-scanner-react-native\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/barcode-qr-code-scanner-react-native\/#primaryimage","url":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2023\/12\/Untitled-design.png","contentUrl":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2023\/12\/Untitled-design.png","width":1920,"height":1080,"caption":"react native scan-1"},{"@type":"BreadcrumbList","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/barcode-qr-code-scanner-react-native\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/200oksolutionssandbox.co.uk\/blog\/"},{"@type":"ListItem","position":2,"name":"Barcode\/QR Code Scanner (React Native)"}]},{"@type":"WebSite","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#website","url":"https:\/\/200oksolutionssandbox.co.uk\/blog\/","name":"","description":"","publisher":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/200oksolutionssandbox.co.uk\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#organization","name":"Web Development Blog | Software Blog | App Blog","url":"https:\/\/200oksolutionssandbox.co.uk\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2026\/01\/200ok_logo.png","contentUrl":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-content\/uploads\/2026\/01\/200ok_logo.png","width":500,"height":191,"caption":"Web Development Blog | Software Blog | App Blog"},"image":{"@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/profile.php?id=61552217825863"]},{"@type":"Person","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#\/schema\/person\/ea0b72006227b3403f5ad825b82ced43","name":"BlogAdmin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/200oksolutionssandbox.co.uk\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/53ecc99d859b4d3444ee1e076f3b5d9da9962836d1c20b3b44d73574f435740d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/53ecc99d859b4d3444ee1e076f3b5d9da9962836d1c20b3b44d73574f435740d?s=96&d=mm&r=g","caption":"BlogAdmin"},"sameAs":["http:\/\/blog.200oksolutions.com"],"url":"https:\/\/200oksolutionssandbox.co.uk\/blog\/author\/blogadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/posts\/165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=165"}],"version-history":[{"count":41,"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/posts\/165\/revisions"}],"predecessor-version":[{"id":791,"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/posts\/165\/revisions\/791"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/media\/174"}],"wp:attachment":[{"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/200oksolutionssandbox.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}