Reputation: 6839
I have been writing my app in Brackets and have been building it with PhoneGap build so i can have Android and iPhone versions from programming on windows.
I am trying to use a barcode scanner that will work in both Android and iPhone:
https://www.npmjs.com/package/phonegap-plugin-barcodescanner-quick
But the directions say to type commands in the CLI, which I have not been using since I have been suing PhoneGap build.
I tried adding the code into my like so:
$(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);
}
);
...
But when I use the PhoneGap desktop app on windows and their Android app the scanner never opens.
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");
Upvotes: 1
Views: 82
Reputation: 4120
This may not really answer your question, but this may help. I have used the same plugin maybe a year ago, based on the npm site it instructs you to use the command line interface to install it. Since the page said to install using command line, then the short snippet of code should work. But since you said you are using the cloud build, there is a different way of adding a plugin in the app, using the config.xml. Here is an example of how you would do this.
Upvotes: 1
Reputation: 2947
There's probably a couple places to look:
Verify that there is in fact a cordova.plugins.barcodeScanner object in the PhoneGap desktop app (maybe add an alert if the object is there):
if (cordova.plugins.barcodeScanner) {alert("Have a scanner object at least...");}
I kind of gave up on the PhoneGap desktop app a while ago -- IIRC it was due to some of the plugins not finding the device correctly.
Upvotes: 0