|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | + |
| 4 | +<head> |
| 5 | + <meta charset="utf-8"> |
| 6 | + <meta name="viewport" content="width=device-width,initial-scale=1.0"> |
| 7 | + <meta name="description" content="Quickly read barcodes with Dynamsoft Barcode Reader from a live camera stream."> |
| 8 | + <meta name="keywords" content="camera based barcode reading"> |
| 9 | + <link rel="canonical" href="https://demo.dynamsoft.com/Samples/DBR/JS/1.hello-world/14.read-video-webview"> |
| 10 | + <title>Dynamsoft Barcode Reader Sample - Read Video WKWebView(iOS)</title> |
| 11 | +</head> |
| 12 | + |
| 13 | +<body style="margin: 0;padding: 0;"> |
| 14 | + <div id="UIElement" style="width: 100vw;height: 100vh;"> |
| 15 | + <span id='lib-load' style='font-size:x-large' hidden>Loading Library...</span> |
| 16 | + <div id="div-ui-container" class="div-ui-container"> |
| 17 | + <div class="dce-video-container"></div> |
| 18 | + </div> |
| 19 | + </div> |
| 20 | + <script src=" https://cdn.jsdelivr.net/npm/[email protected]/dist/dbr.js" ></script> |
| 21 | + <script> |
| 22 | + /** LICENSE ALERT - README |
| 23 | + * To use the library, you need to first specify a license key using the API "license" as shown below. |
| 24 | + */ |
| 25 | + |
| 26 | + Dynamsoft.DBR.BarcodeReader.license = 'DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9'; |
| 27 | + |
| 28 | + /** |
| 29 | + * You can visit https://www.dynamsoft.com/customer/license/trialLicense?utm_source=github&product=dbr&package=js to get your own trial license good for 30 days. |
| 30 | + * Note that if you downloaded this sample from Dynamsoft while logged in, the above license key may already be your own 30-day trial license. |
| 31 | + * For more information, see https://www.dynamsoft.com/barcode-reader/programming/javascript/user-guide/?ver=9.6.20&utm_source=github#specify-the-license or contact [email protected]. |
| 32 | + * LICENSE ALERT - THE END |
| 33 | + */ |
| 34 | + |
| 35 | + let pScanner = null; |
| 36 | + (async function () { |
| 37 | + try { |
| 38 | + await Dynamsoft.DBR.BarcodeReader.loadWasm(); |
| 39 | + window.webkit.messageHandlers.onWasmLoaded.postMessage(""); |
| 40 | + } catch (ex) { |
| 41 | + let errMsg; |
| 42 | + if (ex.message.includes("network connection error")) { |
| 43 | + errMsg = "Failed to connect to Dynamsoft License Server: network connection error. Check your Internet connection or contact Dynamsoft Support ([email protected]) to acquire an offline license."; |
| 44 | + } else { |
| 45 | + errMsg = ex.message || ex; |
| 46 | + } |
| 47 | + console.error(errMsg); |
| 48 | + alert(errMsg); |
| 49 | + } |
| 50 | + })(); |
| 51 | + |
| 52 | + async function startScanner() { |
| 53 | + let scanner = await (pScanner = pScanner || Dynamsoft.DBR.BarcodeScanner.createInstance()); |
| 54 | + await scanner.setUIElement(document.getElementById('div-ui-container')); |
| 55 | + scanner.onUniqueRead = (txt, result) => { |
| 56 | + const format = result.barcodeFormatString; |
| 57 | + window.webkit.messageHandlers.onUniqueRead.postMessage(format + " " + txt); |
| 58 | + }; |
| 59 | + await scanner.show(); |
| 60 | + } |
| 61 | + |
| 62 | + async function stopScanner() { |
| 63 | + let scanner = await pScanner; |
| 64 | + scanner && scanner.hide(); |
| 65 | + } |
| 66 | + </script> |
| 67 | +</body> |
| 68 | + |
| 69 | +</html> |
0 commit comments