0
私は数日間アプリケーションにバーコードリーダープラグインを実装しようとしていましたが、私は運がなかったのです。ボタンを押すと何もしません。私のjavascriptのファイルPhoneGap Barcode Readerプラグインが動作しません
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
},
scan: function() {
console.log('scanning');
var scanner = cordova.require("cordova/plugins/BarcodeScanner");
scanner.scan(function (result) {
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") {
window.plugins.childBrowser.showWebPage(args.text, { showLocationBar: false });
}
*/
}, function (error) {
console.log("Scanning failed: ", error);
});
},
encode: function() {
var scanner = cordova.require("cordova/plugins/BarcodeScanner");
scanner.encode(scanner.Encode.TEXT_TYPE, "http://www.nhl.com", function(success) {
alert("encode success: " + success);
}, function(fail) {
alert("encoding failed: " + fail);
}
);
}};
ザッツ とのindex.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<script type="text/javascript" href="JQuery/jquery-1.12.3.min.js"></script>
<script type="text/javascript" href="JQuery/jquery.mobile-1.4.5.js"></script>
<link rel="stylesheet" type="text/css" href="JQuery/jquery.mobile-1.4.5.css" />
<title>Barcode Scanner Demo</title>
</head>
<body>
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
<p><a href="#" class="topcoat-button" id="scan">SCAN</a></p>
<p><a href="#" class="topcoat-button" id="encode">ENCODE</a></p>
<p id="info"></p>
<h2>OPENING LINKS:</h2>
<p><a href="#" class="topcoat-button" onclick="window.open('http://www.nhl.com', '_blank', 'location=yes');">InAppBrowser</a></p>
<p><a href="#" class="topcoat-button" onclick="window.open('http://www.nhl.com', '_system', 'location=yes');">System Browser</a></p>
<p><a href="#" class="topcoat-button" onclick="window.open('http://www.yahoo.com', '_self', 'location=yes');">This Webview</a></p>
<p><a href="#" class="topcoat-button" onclick="window.plugins.childBrowser.showWebPage('http://www.nhl.com', {});">ChildBrowser</a></p>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="barcodescanner.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</body>
のthatsは私がアプリケーションをデプロイする必要がありますか、私はiOS用のPhoneGapによって提供されるアプリケーションを使用することができますか? ご協力いただければ幸いです。
PhoneGapアプリは、プラグインがインストールされたアプリケーションを配備してくれたと思っています。ありがとう、私はシミュレータや電話を試してみて戻ってきます! – VoodooTech