Callback from InAppBrowser executeScript does not run on IOS. PhoneGap / Cordova

I am working on a Facebook login feature for my Cordova app where I am using InAppBrowser to login. From there, I'm trying to use the executeScript method to grab data from the InAppBroswer and return it to the main application (which is running on the server, not locally on the phone). This works fine on Android, but not on IOS (where none of the callback methods are called). Maybe someone here can help me?

The following JavaScript files are included in the main application on the server.

For IOS:

cordova.js (3.6.4)
cordova_plugins.js
index.js

      

For Android

cordova.js (3.7.0)
cordova_plugins.js
index.js

      

When running the code on Android, I get the following output:

  • The InAppBrowser window opens.
  • I'll sign up on facebook
  • I am redirected to the page shown below (code snippet # 2)
  • I am getting warning from test () function in InAppBrowser (code snippet # 2)
  • I am getting a warning from the first callback function in the main application (code snippet # 1)
  • I am getting a warning from the second callback function in the main application (code snippet # 1)
  • I have registered (result of the code snippet removed from the code below) (code snippet # 1)

When I run the code on IOS, I get the following output:

  • The InAppBrowser window opens.
  • I'll sign up on facebook
  • I am redirected to the page shown below (code snippet # 2)
  • I am getting warning from test () function in InAppBrowser (code snippet # 2)

.. but none of the callbacks are called. Therefore, "d" keeps repeating.

And make them worse. The code worked twice on IOS. But only twice. No change without me.

[change]

It looks like my problem is due to the work flow in the InAppBrowser. This is my current thread.

  • InAppBrowser luanches and the page is redirected to Facebook login api
  • User logs into facebook
  • Go back to my facebook server where code snippet # 2 is running.
  • All callbacks run on android, but not on IOS (see the "Desktop" section for android / ios)

When I tried this thread (which won't work with login) the callbacks will be triggered.

  • Load the InAppBrowser directly into the code in code snippet no.2
  • All callbacks run in all browsers

[/ Edit]

The code I'm using to open the InAppBrowser and then collect data from it looks like this:

function facebookLoginApp() {
var fbloginwin = window.open("/p/ajax/facebookLoginRedirect","_blank",'');

fbloginwin.addEventListener('loadstart',function() {
    clearInterval(loop);
    var loop = setInterval(function() {
        fbloginwin.executeScript( {code: "test();"},function(values) { alert("returnvalue " + values); });

        fbloginwin.executeScript(
            {
                code: "localStorage.getItem('userid')"
            },
            function( values ) {
                var userid = values[ 0 ];
                alert("Loadstart userId: " + userid);
                //Some code removed here for more readable sample..
            }
        );
        fbloginwin.executeScript(
            {
                code: "localStorage.getItem('error')"
            },
            function( values ) {
                var error = values[ 0 ];

                // If a name was set, clear the interval and close the InAppBrowser.
                if ( error ) {
                    clearInterval( loop );
                    fbloginwin.close();
                    alert("Login failed: \n" +error);
                }
            }
        );
    },5000);
});

fbloginwin.addEventListener('loadstop',function() {
    clearInterval(loop);
    var loop = setInterval(function() {
        fbloginwin.executeScript(
            {
                code: "localStorage.getItem('userid')"
            },
            function( values ) {
                var userid = values[ 0 ];
                alert("Loadstop userid " + userid);
                //Some code removed here for more readable sample..
            }
        );
        fbloginwin.executeScript(
            {
                code: "localStorage.getItem('error')"
            },
            function( values ) {
                var error = values[ 0 ];

                // If a name was set, clear the interval and close the InAppBrowser.
                if ( error ) {
                    clearInterval( loop );
                    fbloginwin.close();
                    alert("Login failed: \n" +error);
                }
            }
        );
    },5000);
});
}

      

And the code inside InAppBrowser looks like this:

<html>
<script>
    function test() {
        alert("12341234");
        return "12341234";
    }
    window.localStorage.setItem("userid","12341234");
    window.localStorage.setItem("error","");

    alert(window.localStorage.getItem("userid"));
</script>
<body>
    Login successful. You will be redirected shortly.
</body>
</html>

      

+3


source to share





All Articles