1

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

  • Are you using the CLI to build your project? which platform are you testing? – QuickFix Jan 20 '14 at 08:33
  • Yes, I am using CLI for creating project, adding plugin and build my project. iOS platform and developing for iPhone5s. – Sridhar Boganathan Jan 20 '14 at 09:46
  • in phonegap 3 you should not include phonegap.js, cordova.js nor any plugin javascript file (except if the plugin is not compatible with plugman). maybe you have issues because you manually added the plugin and plugman also includes it? you could also try to un-install and re-install the plugin using the cli. – QuickFix Jan 20 '14 at 13:45
  • I have installed inappbrowser plugin and facebook plugin using CLI without using plugman same as barcodescanner. Both plugins are working fine. How barcodescanner alone is not working. I tried re-installing the same plugins more than 2 times before I post this question. – Sridhar Boganathan Jan 21 '14 at 06:15
  • actually, when you use the cli to install a plugin, you (indirectly) use plugman. Which repo did you use to install the barcode plugin (I've seen that there are several forks) – QuickFix Jan 21 '14 at 08:31
  • I have shared the link (barcodescanner repo) in my post. – Sridhar Boganathan Jan 21 '14 at 09:10
  • seems that you are using the most up to date repository. Anyway you could have a look at this other post (seems outdated but who knows...) http://stackoverflow.com/questions/18142247/phonegap-3-0-0-barcodescanner-plugin – QuickFix Jan 21 '14 at 09:49
  • thanks for responses, you asking me to downgrade the phonegap version to 3.0 – Sridhar Boganathan Jan 21 '14 at 10:42
  • no but you may test the repositories in the other post wich may have a fix for a similar problem – QuickFix Jan 21 '14 at 11:32
  • thanks. I have fixed. the file barcodescanner.js was some run-time issue. I have changed the line of code. It is working now. – Sridhar Boganathan Jan 21 '14 at 13:23

1 Answers1

3

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;
});
Arcayne
  • 1,186
  • 1
  • 15
  • 35