1. #1
    Sencha User
    Join Date
    Dec 2013
    Posts
    2
    Answers
    1
    Vote Rating
    0
    Chepaki is on a distinguished road

      0  

    Default Answered: Sencha Cordova InAppBrowser not working as expected

    Answered: Sencha Cordova InAppBrowser not working as expected


    Hi there,
    Since the iframe inclusion doesn't work well with iOS (no scroll, bouncing the container...), I've tried to implement the cordova InAppBrowser.
    So far I know how to include plugins and build a sencha cordova project. Device ready works fine, but when it comes to InAppBrowser the
    Code:
     window.open(url, '_blank', 'location=yes')
    seems to use the default js method, tried
    Code:
    Cordova.exec(window.open())
    to make sure cordova is handling, but still running default js and opening the cordova browser that I cannot add events or even show alerts on it.
    I've tried even this, knowing how cordova execute methods:
    Code:
    Cordova.exec(successFunction, failFunction, "InAppBrowser", "open", [url, '_blank','location=yes']);
    It does open the InAppBrowser, but none of the listeners, given at the Official Cordova website, could be added. such as: loadstart, loadstop, exit or alerts could be shown.
    Any help is really appreciated.

  2. Hi Ross,
    Thanks for your answer but, it's exactly what I'm doing.
    Anyway, I tried to isolate the problem, re-installed cordova and created a new project and it worked fine for me.
    When looking for the difference between my project with failed InAppBrowser and the clean one I've found that the source of problem was that in my project I've done a
    Code:
    sencha cordova remove
    multiple times, it does in fact, remove cordova folder from the current project but keep this
    Code:
    "js": [      {
             "path": "cordova.js",
             "remote": true
          },...
    in app.json so when I make a
    Code:
    sencha cordova init com.domain.AppName
    it add another dependecy dor cordova.js (the code bellow will be duplicated as many times as you did cordova remove/init) and so in the index.html
    so at the beginning the app keep loading the cordova.js as many times as it's called, and there comes the problem, the inAppBrowser won't be loaded on time and window.open would call the default js method or something else irregular that prevent cordova plugin from working as expected (gave me a hard time with file transfer plugin as well).
    I hope that this helps someone out there and save the time spent looking elsewhere...

  3. #2
    Sencha - Sencha Touch Dev Team
    Join Date
    Oct 2010
    Posts
    86
    Answers
    8
    Vote Rating
    21
    RossGerbasi will become famous soon enough RossGerbasi will become famous soon enough

      0  

    Default


    I think this might be a question for the cordova folks unless it turns out to be architect specific, but everything seems to be working fine for me. I am not running through this in Architect but here are my steps from terminal.

    1. sencha -sdk /{path}/{to}/{sencha-touch-sdk}/ generate app TestApp TestApp
    2. cd TestApp
    3. sencha cordova init com.test.TestApp
    4. cd cordova
    5. cordova plugin add org.apache.cordova.inappbrowser
    6. cd ..
    7. Edit app.js (as shown below)
    8. sencha app build -run native


    My app.js looks like this

    Code:
    Ext.application({
        name: 'TestApp',
    
    
        launch: function() {
            Ext.fly('appLoadingIndicator').destroy();
            Ext.Viewport.add({
                items: {
                    xtype: 'button',
                    text: 'pop it',
                    handler: function() {
                        var ref = window.open('http://apache.org', '_blank', 'location=yes'),
                            handler = function(e) {
                                console.log('event: ' + e.type);
                            }
                        
                        ref.addEventListener('loadstart', handler);
                        ref.addEventListener('loadstop', handler);
                    }
                }
            });
        }
    });
    I am running node v0.10.26, cordova 3.4.1-0.1.0 and sencha touch 2.3.1a. Though I have tested this without sencha touch at all and it also works fine. When I tap the 'pop it' button I get a 'event: loadstart' followed by 'event: loadstop'.
    Ross Gerbasi
    Sencha Inc | Senior Software Engineer

  4. #3
    Sencha User
    Join Date
    Dec 2013
    Posts
    2
    Answers
    1
    Vote Rating
    0
    Chepaki is on a distinguished road

      0  

    Default Duplicated call for cordova.js in app.json

    Duplicated call for cordova.js in app.json


    Hi Ross,
    Thanks for your answer but, it's exactly what I'm doing.
    Anyway, I tried to isolate the problem, re-installed cordova and created a new project and it worked fine for me.
    When looking for the difference between my project with failed InAppBrowser and the clean one I've found that the source of problem was that in my project I've done a
    Code:
    sencha cordova remove
    multiple times, it does in fact, remove cordova folder from the current project but keep this
    Code:
    "js": [      {
             "path": "cordova.js",
             "remote": true
          },...
    in app.json so when I make a
    Code:
    sencha cordova init com.domain.AppName
    it add another dependecy dor cordova.js (the code bellow will be duplicated as many times as you did cordova remove/init) and so in the index.html
    so at the beginning the app keep loading the cordova.js as many times as it's called, and there comes the problem, the inAppBrowser won't be loaded on time and window.open would call the default js method or something else irregular that prevent cordova plugin from working as expected (gave me a hard time with file transfer plugin as well).
    I hope that this helps someone out there and save the time spent looking elsewhere...