{"id":431,"date":"2025-09-12T08:31:56","date_gmt":"2025-09-12T08:31:56","guid":{"rendered":"https:\/\/datasymbol.com\/blog\/?p=431"},"modified":"2025-09-12T09:11:10","modified_gmt":"2025-09-12T09:11:10","slug":"how-to-play-a-beep-sound-when-scanning-a-barcode-on-ios-iphone-ipad","status":"publish","type":"post","link":"https:\/\/datasymbol.com\/blog\/2025\/09\/12\/how-to-play-a-beep-sound-when-scanning-a-barcode-on-ios-iphone-ipad\/","title":{"rendered":"How to Play a Beep Sound When Scanning a Barcode on iOS (iPhone, iPad)"},"content":{"rendered":"\n<figure class=\"wp-block-image alignright size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"680\" src=\"https:\/\/datasymbol.com\/blog\/wp-content\/uploads\/2025\/09\/iphone-scan-barcode-beep3.jpg\" alt=\"\" class=\"wp-image-444\" style=\"width:600px\" srcset=\"https:\/\/datasymbol.com\/blog\/wp-content\/uploads\/2025\/09\/iphone-scan-barcode-beep3.jpg 800w, https:\/\/datasymbol.com\/blog\/wp-content\/uploads\/2025\/09\/iphone-scan-barcode-beep3-300x255.jpg 300w, https:\/\/datasymbol.com\/blog\/wp-content\/uploads\/2025\/09\/iphone-scan-barcode-beep3-768x653.jpg 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p>When using our <strong><a href=\"https:\/\/www.datasymbol.com\/barcode-web-sdk\/barcode-scanner-for-web.html\">Barcode Scanner for Website SDK<\/a><\/strong>, you may encounter the following issue:<\/p>\n\n\n\n<p>When the scanner is created and started immediately upon navigating to the scanner page, the <strong>beep sound does not play<\/strong> after a barcode is decoded.<\/p>\n\n\n\n<p>You can test this behavior here:<br>   <a href=\"https:\/\/websdk.datasymbol.com\/\">https:\/\/websdk.datasymbol.com\/<\/a><\/p>\n\n\n\n<p class=\"has-large-font-size\"><strong>Why This Happens on iOS<\/strong><\/p>\n\n\n\n<p>iOS requires some form of <strong>user interaction<\/strong> before a webpage is allowed to play sound.<br>This could be a click, a tap, a scroll, etc.<br>If the scanner is created and started automatically, there is no user interaction yet \u2014 so iOS blocks the sound.<\/p>\n\n\n\n<p class=\"has-large-font-size\"><strong>The Solution (The Trick)<\/strong><\/p>\n\n\n\n<p>The trick is simple: <strong>don\u2019t create the scanner immediately<\/strong> after the page loads.<br>Instead, display a button such as <strong>&#8220;SCAN&#8221;<\/strong>.<br>When the user clicks this button, we create the scanner \u2014 and in the same event handler, we \u201cunlock\u201d the ability to play sounds.<\/p>\n\n\n\n<p>Example Code<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"line-height:1\"><code>function OnScannerButtonClick() {\n\tbeepObj = new Audio(\"\");\n\tbeepObj.play();\n\tbeepObj.src = \"https:\/\/websdk.datasymbol.com\/audio\/beep1.mp3\";\n\n\tdocument.getElementById('scanbutton').style.display = 'none';\n\tCreateScanner();\n}<\/code><\/pre>\n\n\n\n<p class=\"has-large-font-size\"><strong>Explanation<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We create a new <code>Audio<\/code> object and call <code>play()<\/code> before setting its source.<\/li>\n\n\n\n<li>Since the object has no source yet, <strong>no sound is actually played<\/strong>, but iOS now considers the page as having a valid user interaction.<\/li>\n\n\n\n<li>After this, iOS allows JavaScript to play sounds freely.<\/li>\n<\/ul>\n\n\n\n<p>Finally, in the <code>onBarcodeReady<\/code> event handler (which fires after a barcode is successfully decoded), we simply call:<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"line-height:0.1\"><code>beepObj.play();<\/code><\/pre>\n\n\n\n<p>This time, the sound will play correctly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-normal-font-size\">Example<\/h3>\n\n\n\n<p>You can see the full source code here:<br><a href=\"https:\/\/websdk.datasymbol.com\/appsound\/js\/main.js\">https:\/\/websdk.datasymbol.com\/appsound\/js\/main.js<\/a><\/p>\n\n\n\n<p>And you can test the live demo here:<br><a href=\"https:\/\/websdk.datasymbol.com\/appsound\/\">https:\/\/websdk.datasymbol.com\/appsound\/<\/a><\/p>\n\n\n\n<iframe src='https:\/\/websdk.datasymbol.com\/appsound\/' height=700>\n<\/iframe>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<!-- READY TO GET STARTED START -->\n<div class='blue_rect blue_rect1' style='margin-top:3em; padding:2em;'>\n\n\t<h1 class='h15class'>Ready to get started?<\/h1>\n\n\t<div class='v18' style='width:60%'>\n\t\tIntegrate the DataSymbol Web SDK into your Web application in under an hour. Check out our tutorials, documentation, source code, or download the demo app to get started right away.\n\t<\/div>\n\n\t<br><br>\n\t<a class=\"anybutton anybutton3\" href=\"https:\/\/www.datasymbol.com\/barcode-web-sdk\/barcode-scanner-for-web.html\">Barcode Scanner Web SDK<\/a>\n<\/div>\n<!-- READY TO GET STARTED STOP -->\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When using our Barcode Scanner for Website SDK, you may encounter the following issue: When the scanner is created and started immediately upon navigating to the scanner page, the beep sound does not play after a barcode is decoded. You can test this behavior here: https:\/\/websdk.datasymbol.com\/ Why This Happens on iOS iOS requires some form [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":444,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-431","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-barcode-scanner-web-sdk"],"_links":{"self":[{"href":"https:\/\/datasymbol.com\/blog\/wp-json\/wp\/v2\/posts\/431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/datasymbol.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/datasymbol.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/datasymbol.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/datasymbol.com\/blog\/wp-json\/wp\/v2\/comments?post=431"}],"version-history":[{"count":10,"href":"https:\/\/datasymbol.com\/blog\/wp-json\/wp\/v2\/posts\/431\/revisions"}],"predecessor-version":[{"id":446,"href":"https:\/\/datasymbol.com\/blog\/wp-json\/wp\/v2\/posts\/431\/revisions\/446"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/datasymbol.com\/blog\/wp-json\/wp\/v2\/media\/444"}],"wp:attachment":[{"href":"https:\/\/datasymbol.com\/blog\/wp-json\/wp\/v2\/media?parent=431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/datasymbol.com\/blog\/wp-json\/wp\/v2\/categories?post=431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/datasymbol.com\/blog\/wp-json\/wp\/v2\/tags?post=431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}