iosphonegap-pluginsbarcode-scannerchildbrowser

Phonegap: BarcodeScanner & Childbrowser plugins


I'm facing a problem using this 2 PhoneGap plugins: "BarcodeScanner" & "ChildBrowser" (inside an iOS app, with XCode 4 & PhoneGap 2.0).

I've a button "Scan" on my app UI. When the user clic on this button, the barcode scanner is launched.

So, in the Success function of the barcode scanner callback, I need to open the recovered URL from the scan in a new Childbrowser window (inner the app).

But the new Childbrowser window is never been opened, while the console displays "Opening Url : http://fr.wikipedia.org/" (for example).

Here is my JS part of code:

$("#btnStartScan").click(function() {
       var scanBarcode = window.plugins.barcodeScanner.scan(
                           function(result) {
                                    if (!result.cancelled){
                                         openUrl(result.text);
                                    }
                            },
                            function(error) {
                                    navigator.notification.alert("scanning failed: " + error);
       });
 });

function openUrl(url)
{
      try {
          var root = this;
          var cb = window.plugins.childBrowser;

          if(cb != null) {
                    cb.showWebPage(url);
          }
          else{
              alert("childbrowser is null");
          }
       }
       catch (err) {
           alert(err);
       }
}

And all works fine if I call my openURL() function inside a Confirm alert callback for example, like this:

if (!result.cancelled){
        navigator.notification.confirm("Confirm?",
                                       function (b) {
                                              if (b === 1) {
                                                   openUrl(result.text);
                                              }
                                       },
                                       'Test',
                                       'Yes, No');
 } 

But I need to launch the ChildBrowser window directly after a scan, without any confirm alert etc.

Does anybody know how to solve this please?


Solution

  • I also have this same problem.

    Solve it by set timeout.

       var scanBarcode = window.plugins.barcodeScanner.scan(
                           function(result) {
                                    if (!result.cancelled){
                                         setTimeout(function(){ openUrl(result.text); },500);
                                    }
                            },
                            function(error) {
                                    navigator.notification.alert("scanning failed: " + error);
       });