-1

I've got a mobile web app (not iOS) that I'm trying to use the share dialogue on. I'm logging the output of the whole process, so I can see where the system is breaking down. When I test on a desktop browser, the whole thing works perfectly. However, when I test on my iPhone, the system stops at FB.login(). Looking at the logs, my webapp runs FB.getLoginStatus() just fine. The response is an object with status="unknown". I've got a callback function which logs "getLoginStatus response.status != connected" and then attempts to run FB.login(function(response){}). The first line of of the callback is an attempt to log "FB.login response". That line never gets logged. Nothing happens. It's as if the webapp gets to FB.login() and then doesn't do anything. I've tried running other functions in that spot (like FB.api()) and they give me the correct errors (no authToken). Any ideas what might be going on?

Example code:

FB.getLoginStatus(function(response) {
    console.log('getLoginStatus response:');
    console.log(response);
    if(response.status != 'connected') {
        console.log('getLoginStatus response.status != connected'); // THIS IS THE LAST THING I SEE IN MY CONSOLE
        FB.login(function(response) {
            console.log('FB.login response');
            console.log(response);
            if(response.status != 'connected') {
                console.log('Failed to log in');
            } else {
                console.log('You\'re logged in');
            }
        });
    } else {
        console.log('You\'re logged in');
    }
});

Yields the following logs:

getLoginStatus response:
Object {status: "unknown", authResponse: null} 
getLoginStatus response.status != connected 

To clarify: No error response and no further logs after this. Repeated clicks on the share button yield the exact same results.

1 Answers1

1

OK - found out the issue. What I omitted in the initial question was that this was all being called within an Angular.js app. Well, turns out that the FB.login() function needed to be called in the next cycle. So by simply wrapping the FB.login function in $timeout (as per the answers here: AngularJS : Prevent error $digest already in progress when calling $scope.$apply()) allowed it to be run in the next cycle and everything now works. End code looks like this:

FB.getLoginStatus(function(response) {
    console.log('getLoginStatus response:');
    console.log(response);
    if(response.status != 'connected') {
        console.log('getLoginStatus response.status != connected'); 
        $timeout(function(){ //THIS IS THE FIX
            FB.login(function(response) {
                console.log('FB.login response');
                console.log(response);
                if(response.status != 'connected') {
                    console.log('Failed to log in');
                } else {
                    console.log('You\'re logged in');
                }
            });
        });
    } else {
        console.log('You\'re logged in');
    }
});
Community
  • 1
  • 1