Pregunta

I am developing ios native application using Phonegap. This application has barcode scanning feature. It was working fine with phonegap version 2.9.0. Now, it is not working after I upgrade phonegap version 3.3.0.

It says "module cordova/plugin/BarcodeScanner not found" if I use the following code

var scanner = cordova.require('cordova/plugin/BarcodeScanner');
scanner.scan(function1, function2);

It says undefined If I use the following code

window.plugins.barCodeScanner.scan(func1, func2);

It says undefined If I use the following code

cordova.plugins.barcodeScanner.scan(func1, func2);

I used this link for this implementation. Please let me what am I doing wrong?

I have included barcodescanner.js and it is loaded when the app is loaded. I am sure about. Also I am not getting any errors while building.

--Sridhar

¿Fue útil?

Solución

It is fixed. There is was run-time issue in barcodescanner.js. I found and fixed. It is working fine. The changed code.

cordova.define("cordova/plugin/BarcodeScanner", function (require, exports, module) {    
var exec = require("cordova/exec");
function BarcodeScanner() {
    this.Encode = {
    TEXT_TYPE: "TEXT_TYPE",
    EMAIL_TYPE: "EMAIL_TYPE",
    PHONE_TYPE: "PHONE_TYPE",
    SMS_TYPE: "SMS_TYPE"
        //  CONTACT_TYPE: "CONTACT_TYPE",  // TODO:  not implemented, requires passing a Bundle class from Javascript to Java
        //  LOCATION_TYPE: "LOCATION_TYPE" // TODO:  not implemented, requires passing a Bundle class from Javascript to Java
    };
};
BarcodeScanner.prototype.scan = function (successCallback, errorCallback) {
    if (errorCallback == null) {
        errorCallback = function () {
        };
    }
    if (typeof errorCallback != "function") {
        console.log("BarcodeScanner.scan failure: failure parameter not a function");
        return;
    }
    if (typeof successCallback != "function") {
        console.log("BarcodeScanner.scan failure: success callback parameter must be a function");
        return;
    }
    exec(successCallback, errorCallback, 'BarcodeScanner', 'scan', []);
};
BarcodeScanner.prototype.encode = function (type, data, successCallback, errorCallback, options) {
    if (errorCallback == null) {
        errorCallback = function () {
        };
    }
    if (typeof errorCallback != "function") {
        console.log("BarcodeScanner.encode failure: failure parameter not a function");
        return;
    }
    if (typeof successCallback != "function") {
        console.log("BarcodeScanner.encode failure: success callback parameter must be a function");
        return;
    }
    exec(successCallback, errorCallback, 'BarcodeScanner', 'encode', [
        {"type": type, "data": data, "options": options}
    ]);
};
var = new BarcodeScanner();
module.exports = barcodeScanner;
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top