首页 文章

PhoneGap Build插件

提问于
浏览
1

我一直在使用Brackets编写我的应用程序,并且已经使用PhoneGap构建它,因此我可以通过Windows上的编程获得Android和iPhone版本 .

我正在尝试使用可在Android和iPhone上运行的条形码扫描仪:

https://www.npmjs.com/package/phonegap-plugin-barcodescanner-quick

但是指示说在CLI中键入命令,因为我一直在使用PhoneGap构建,所以我没有使用它 .

我尝试将代码添加到我的喜欢中:

$(document).ready(function () {

    //todo get user id from local storage
    var searchTerm = window.localStorage.getItem("search");
    var userID = window.localStorage.getItem("userID");
    var history = [];
    var lastUpdate = window.localStorage.getItem("searchUpdateTime");

    //todo scan stuff
    cordova.plugins.barcodeScanner.scan(
      function (result) {
          alert("We got a barcode\n" +
                "Result: " + result.text + "\n" +
                "Format: " + result.format + "\n" +
                "Cancelled: " + result.cancelled);
      }, 
      function (error) {
          alert("Scanning failed: " + error);
      }
   );
...

但是,当我在Windows和他们的Android应用程序上使用PhoneGap桌面应用程序时,扫描仪永远不会打开 .

Update:

Tried adding this code to my project for testing purposes, based on one of the answers below, but it returned nothing:

  //todo scan stuff
    if (cordova.plugins.barcodeScanner) {alert("Have a scanner object at least...");}

    else{alert("nope");

2 回答

  • 1

    这可能不能真正回答你的问题,但这可能有所帮助 . 我可能在一年前使用相同的插件,基于npm site它指示您使用命令行界面来安装它 . 由于页面说使用命令行安装,因此代码的短片段应该可以工作 . 但是既然你说你正在使用 Cloud 构建,那么使用config.xml在应用程序中添加插件有一种不同的方式 . 这是一个如何做this的例子 .

  • 0

    可能有几个地方要看:

    if (cordova.plugins.barcodeScanner) {alert("Have a scanner object at least...");}

    我刚才放弃了PhoneGap桌面应用程序 - IIRC是因为某些插件没有正确找到设备 .

相关问题