【问题标题】:Phonegap barcodescanner pluginPhonegap 条码扫描器插件
【发布时间】:2015-09-29 13:30:43
【问题描述】:

我正在使用 cordova 开发一个应用程序,我想使用以下条码扫描器:

https://github.com/phonegap/phonegap-plugin-barcodescanner

我安装了插件:

phonegap plugin add com.phonegap.plugins.barcodescanner

现在插件文件夹中有一个名为 com.phonegap.plugins.barcodescanner 的新子文件夹。

在这一点上似乎是正确的。

但是现在当我在手机上运行该应用程序时,我会得到一个页面

cordova.require object should exist
BarcodeScanner plugin should exist

module cordova/plugin/BarcodeScanner not found

我的 config.xml 甚至还没有以下行:

<gap:plugin name="com.phonegap.plugins.barcodescanner"/>

但即使我添加了这一行,它也不会改变任何事情。

我需要做什么才能成功加载插件?

【问题讨论】:

  • 贴一些你应用的代码,也许有一些线索
  • 我不能发布所有内容,因为它太多了,我不明白这有什么用。添加插件中的子文件夹后,该应用程序不再工作,而代码保持不变。我不认为未使用的插件应该改变应用程序的行为,但似乎确实如此。也许有一个很好的理由,我只是没有意识到。如果你能告诉我代码的哪一部分可能很有趣,我可以在这里发布。感谢您的回复。
  • 您是否在代码中调用插件 (cordova.plugins.barcodeScanner.scan(...);)?
  • 不,没有调用,没有通过脚本标签导入,在 confix.xml 中没有条目。从字面上看没有,但它仍然会破坏我的应用程序。

标签: cordova cordova-plugins barcode-scanner


【解决方案1】:

我有一个带有这个插件的应用程序,这是我的代码。

当您的设备准备就绪时:

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

       `scanner.scan( function (result) { 
        window.open(result.text, '_system', 'location=yes');
        /*
        alert("We got a barcode\n" + 
        "Result: " + result.text + "\n" + 
        "Format: " + result.format + "\n" + 
        "Cancelled: " + result.cancelled);  */

       console.log("Scanner result: \n" +
            "text: " + result.text + "\n" +
            "format: " + result.format + "\n" +
            "cancelled: " + result.cancelled + "\n");
        document.getElementById("info").innerHTML = result.text;
        console.log(result);
        /*
        if (args.format == "QR_CODE") {
            // Your code
        }
        */

    }, function (error) { 
        console.log("Scanning failed: ", error); 
    } );`

【讨论】:

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