【问题标题】:Phonegap Build: Barcode Scanner Plugin doesn't workPhonegap Build:条码扫描器插件不起作用
【发布时间】:2013-10-13 20:32:44
【问题描述】:

我正在尝试使用 Phonegap Build 在我的 jQuery Mobile 应用程序构建中使用 Phonegap Build Barcode Scanner Plugin,但它不起作用。

这里有一个示例页面:

<!DOCTYPE html>
<html lang="pt-br">
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, maximum-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>Save Points</title>

    <!-- CSS -->
    <link rel="stylesheet" href="css/jquery.mobile-1.3.1.min.css">  
    <link rel="stylesheet" href="css/themes/savepoints.min.css" />
    <link rel="stylesheet" href="css/codiqa.ext.css">

    <!-- jQuery and jQuery Mobile -->
    <script type="text/javascript" src="phonegap.js"></script>
    <script type="text/javascript" src="barcodescanner.js"></script>
    <script src="js/jquery-1.9.0.js"></script>
    <script src="js/codiqa.ext.js"></script>
    <script src="js/jquery.mobile-1.3.1.min.js"></script>
</head>
<body>
<div data-role="page" id="page_sample" data-theme="a">      
    <div data-role="content">
       <div id="content">       
            <p><a href="#" class="topcoat-button" id="scan">SCAN</a></p>
            <p><a href="#" class="topcoat-button" id="encode">ENCODE</a></p>
       </div>
    </div>
</div>
</body>
</html>

在文件 codiqa.ext.js 我有这个:

$(document).on('pageshow', '#page_sample', function(e) {    
        $('#scan').click(function () {
            alert('scanning');

            var scanner = cordova.require("cordova/plugin/BarcodeScanner");

            alert(scanner);

            scanner.scan( function (result) { 
                alert("We got a barcode\n" + 
                "Result: " + result.text + "\n" + 
                "Format: " + result.format + "\n" + 
                "Cancelled: " + result.cancelled);  

               alert("Scanner result: \n" +
                    "text: " + result.text + "\n" +
                    "format: " + result.format + "\n" +
                    "cancelled: " + result.cancelled + "\n");
                alert(result);
            },function (error) { 
                console.log("Scanning failed: ", error); 
            });
        });
    });

我的 config.xml 文件:

<!-- Barcode Scanner -->
<gap:plugin name="com.phonegap.plugins.barcodescanner" version="1.0.2" />

调试这段代码,发现脚本停在了一行:

var scanner = cordova.require("cordova/plugin/BarcodeScanner");

我正在关注官方文档,上面说我不必将文件barcodescanner.js 放在我的项目中,只需将其引用到html 标头中即可。

有人知道我做得好吗?

提前致谢。

更新

问题已解决!我应该使用

<preference name="phonegap-version" value="3.0.0" />

而不是

<preference name="phonegap-version" value="2.9.0" />

【问题讨论】:

    标签: jquery jquery-mobile phonegap-plugins barcode-scanner phonegap-build


    【解决方案1】:

    问题已解决!

    我应该使用

    <preference name="phonegap-version" value="3.0.0" />
    

    而不是

    <preference name="phonegap-version" value="2.9.0" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-11
      • 2012-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-30
      • 1970-01-01
      相关资源
      最近更新 更多