Question

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?

Was it helpful?

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);
   });

OTHER TIPS

I'm running into the exact same problem.

My application also has another mechanism to show a webpage besides the barcode reader and when I do that action I can see that the barcode-related page HAD loaded, but it never was shown.

In ChildBrowserViewController.m, I'm looking at the last line of loadURL() which is webView.hidden = NO; and I'm thinking that the child browser is set visible after we barcode but something about the barcode reader window caused the child browser to get set to the wrong z-order, but I'm not familiar enough with the sdk to know how to test that or try to bring it to the front.

Hope this helps target a potential area.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top