How to call a Cordova plugin method from Meteor?

This is a newbie to Meteor. I cannot call Cordova plugin methods from Meteor.

This is the plugin I care about:
http:// plugins.cordova.io/#/package/com.phonegap.plugins.barcodescanner

I added the package to the command line:
meteor add cordova: [email protected]. 1

The following is my javascript code. What finally happens is that at startup, the onCallback method loads, but the barcode scanning does not occur, and onSuccess and onError are not called. I have tried similar methods with Other cordova packages, but no effect. I also tried to replace all lower limits with’cordova.plugins.barcodeScanner.scan’ in cordova.call,’barcodeScanner.scan’,’com.phonegap.plugins.barcodescanner.scan’ and other changes Body, but in vain.

if (Meteor.isCordova) {
Meteor.startup(function () {
cordova = new Cordova();< br /> cordova.addEventListener('deviceready', function() {
function onSuccess(result) {
alert("We got a barcode " +
"Result: "+ result .text + " " +
"Format: "+ result.format + " " +
"Cancelled:" + result.cancelled);
}
< br /> function onError(error) {
alert("Scanning failed: "+ error);
}

function onCallback(msg) {
alert("Callback!" + msg);
}

cordova.call(
'cordova.plugins.barcodeScanner.scan',
[onSuccess, onError],
onCallback );
});
}
}

in In the Meteor Cordova app, Meteor.startup is used as a deviceready event, so you don’t need a deviceready event. Also, cordova is already defined in the global context, so you don’t need to try to create a new instance. Finally, read the plugins on plugins.cordova.io The page explains that the plugin has been named cordova.plugins.barcodeScanner. In your case, the scanning method of the barcodeScanner class is particularly important. You can use it in the meteor below, but please note that when the application starts from a complete stop , This will open the scanner, so it is better to call the scan method from something such as a click event.

if(Meteor.isCordova){
Meteor.startup(function () {
cordova.plugins.barcodeScanner.scan(
function (result) {
alert("We got a ba rcode " +
"Result: "+ result.text + " " +
"Format:" + result.format + " " +
"Cancelled: "+ result.cancelled);
},
function (error) {
alert("Scanning failed: "+ error);
}
);
});
}

This is a newbie to Meteor. I cannot call Cordova plugin methods from Meteor.

This is The plugin I care about:
http://plugins.cordova.io/#/package/com.phonegap.plugins.barcodescanner

I added the package in the command line:
meteor add cordova: [email protected]

The following is my javascript code. What finally happens is that at startup, the onCallback method loads, but barcode scanning does not occur, nor does it Call onSuccess and onError. I tried similar methods with other cordova packages, but nothing worked. I also tried replacing all lower limits with’cordova.plugins.barcodeScanner.scan’ in cordova.call,’barcodeScanner.scan’,’ com.phonegap.plugins.barcodescanner.scan’ and other variants, but in vain.

if (Meteor.isCordova) {
Meteor.startup(function () {
cordova = new Cordova();
cordova.addEventListener( 'deviceready', function() {
function onSuccess(result) {
alert("We got a barcode " +
"Result: "+ result.text + " " +
"Format: "+ result.format + " " +
"Cancelled:" + result.cancelled);
}

function onError(error ) {
alert("Scanning failed: "+ error);
}

function onCallback(msg) {
alert("Callback!" + msg);
}

cordova.call(
'cordova.plugins.barcodeScanner.scan',
[onSuccess, onError],
onCallback);
});
}
}

In the Meteor Cordova app, Meteor.startup is used as the deviceready event, so you No deviceready event is required. Also, cordova is already defined in the global context, so you don’t need to try to create a new instance. Finally, read the plugin page on plugins.cordova.io explaining that the plugin is named cordova.plugins.barcodeScanner. Before you In the case of barcodeSca The scanning method of the nner class is particularly important. You can use it in the meteor below, but please note that this will open the scanner when the app is started from a complete stop, so it is better to call the scan from something like a click event Method.

if(Meteor.isCordova){
Meteor.startup(function () {
cordova.plugins.barcodeScanner.scan(
function (result) {
alert("We got a barcode " +
"Result: "+ result.text + " " +
"Format:" + result.format + " " +
"Cancelled: "+ result.cancelled);
},
function (error) {
alert("Scanning failed:" + error);
}
);
});
}

Leave a Comment

Your email address will not be published.