【问题标题】:IBM Mobilefirst 7.0- Barcode Scanner for Hybrid App is not workingIBM Mobilefirst 7.0- 混合应用程序条码扫描仪不工作
【发布时间】:2015-06-13 03:41:08
【问题描述】:

在这里,我正在尝试使用 IBM Mobilefirst 构建一个混合应用程序,我想在其中使用 Barcode Scanner。为此,我点击了以下链接。

https://www.ibm.com/developerworks/community/blogs/WASFAQs/entry/using_a_barcode_scanner_with_worklight?lang=en

还有,这是我的 index.html:

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Barcode</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
        <!--
            <link rel="shortcut icon" href="images/favicon.png">
            <link rel="apple-touch-icon" href="images/apple-touch-icon.png"> 
        -->
        <link rel="stylesheet" href="css/main.css">
        <script>window.$ = window.jQuery = WLJQ;</script>
<script>
$('#scanButton').bind('click', doScan);
function doScan(){
alert("Hello");
alert(cordova.exec(onScanSuccess, onScanFailure, 'BarcodeScanner', 'scan', []));
}
function onScanSuccess(result) {
alert("We got a barcode\n" +
    "Result: " + result.text + "\n" +
    "Format: " + result.format + "\n" +
    "Cancelled: " + result.cancelled);
}
function onScanFailure(error) {
alert("Scanning failed: " + error);
}
</script>
    </head>
    <body style="display: none;">
        <!--application UI goes here-->
        <script src="js/initOptions.js"></script>
        <script src="js/main.js"></script>
        <script src="js/messages.js"></script>
        <h1>Barcode scanner</h1>
        <button type="button" id="scanButton" >Scan</button>
    </body>
</html>

【问题讨论】:

  • 如果您懒得解释这怎么行不通,我们也懒得去尝试猜测问题可能是什么。
  • 当我点击扫描按钮时,doScan 函数正在调用,doScan cordova.exex() 内部没有调用,也没有显示任何错误
  • 你定义了doScan AFTER你试图做绑定,这意味着doScan还没有被定义,你绑定到一个不存在的函数。如果您甚至完成了基本调试:打开 JS 控制台,您就会看到该错误。它会杀死其余的 JS 代码块
  • 之前我尝试过使用 onclick 功能。在这种情况下,它也不起作用

标签: android ibm-mobilefirst


【解决方案1】:

cordova.exec 失败的主要原因是您错误地使用插件引用配置了 config.xml。

您没有将 LogCat 日志添加到您的问题中 - 您会看到您面临的实际错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-11
    • 1970-01-01
    • 2013-04-17
    相关资源
    最近更新 更多