如何在移动web应用程序中集成Phonegap插件,用于条形码扫描仪



我们正在尝试在我们的移动web应用程序中集成用于条形码扫描仪的phonegap插件。有人能帮我整合这个吗?

我补充道,Phonegap.js和cardova.js,插件试图安装,但它需要很多时间,而且没有安装。。

这是我的HTML内容

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Bar code Reader</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="barcodescanner.js"></script>
<script src="cordova.js"></script>
<script>
$(document).ready(function () {
app.initialize();
});
function clickScan() {
console.log("I am now scanning");
window.plugins.barcodeScanner.scan(function (result) {
alert("We got a barcoden" +
"Result: " + result.text + "n" +
"Format: " + result.format + "n" +
"Cancelled: " + result.cancelled);
}, function (error) {
alert("Scanning failed: " + error);
});
}
</script>
</head>
<body>
<button id="scan" style="padding: 10px;" onclick="clickScan">Scan!</button>
</body>
</html>

按照以下步骤

1.下载并安装Node.js

2.在命令提示符$ sudo npm install -g phonegap 上运行此命令

3.创建一个名为hello $ phonegap create hello com.example.hello HelloWorld 的应用程序

4.转到hello目录$ cd hello

5.选择了你的平台,我向你展示了ios,你也可以为Android构建

 $ phonegap build ios
[phonegap] detecting iOS SDK environment...
[phonegap] using the local environment
[phonegap] compiling iOS...
[phonegap] successfully compiled iOS app

6.添加要添加phonegap local plugin add https://github.com/phonegap-build/BarcodeScanner.git 的插件

7.要远程编译您的应用程序,请在构建命令前面加上额外的远程命令:$ phonegap remote install ios # ...or... $ phonegap remote run ios

以下是条形码扫描仪插件的用法示例:

<!DOCTYPE HTML>
<html>
<head>
  <title>Barcode Scanner DEMO</title>
<script type="text/javascript" src="plugins/plugin-loader.js"></script>   
<script type="text/javascript" charset="utf-8">
monaca.viewport({width : 320});
function scanBarcode() {
  window.plugins.barcodeScanner.scan( function(result) {
          alert("We got a barcoden" +
                    "Result: " + result.text + "n" +
                    "Format: " + result.format + "n" +
                    "Cancelled: " + result.cancelled);
      }, function(error) {
          alert("Scanning failed: " + error);
      }
);
}
</script>
</head>
<hr> BarcodeReader DEMO <hr><br>
<input type="button" onClick ="scanBarcode()" value ="Scan" />
</body>
</html>

最新更新