iosfacebooktitaniumtitanium-modules

Ti.Facebook doesn't open authorize with FB app installed


EDIT: DEAR PEOPLE FROM THE FUTURE, trey-jones has fixed this issue by implementing setLoginBehavior, FBSDKLoginNative seems to have issues on FB's end not with the module.

Environment:

MacOS X 10.10.5
Ti SDK 5.1.1.GA - 5.1.2.GA
iOS 9.2
Ti.Facebook 5.0.0 - 5.0.1

My project settings (tiapp.xml) are fine (it works on every other case on both iOS and Android).

Code I'm using to invoke the login:

var fb = require('facebook');
fb.initialize();
fb.authorize(); 

If the Facebook app is installed to the device the fb.authorize() doesn't open up. I did not see any iOS system level messages when this happened either.

Has anyone else had luck using fb.authorize with the new sdk on iOS devices WITH the app installed. With no fb app on the system it correctly opens the browser based view.

EDIT: I have managed a workaround for this (it is not pretty) based on the fact that login works with AppC's KitchenSink.

The workaround is to add a Ti.FB loginButton to the code, doesn't matter if its not visible, initializing this will fix whatever is causing custom login's .authorize() to not work.

//Workaround button:
if(OS_IOS){
    var fbHaxBtn = fb.createLoginButton({
        readPermissions: ['email'],
        visible: false
    });
}
//It needs to be added to the window/doesn't need to be visible though
$.login_window.add(fbHaxBtn);

//Then in our custom button's code, we can fire as normal:
function doLoginClick{
    fb.initialize(); //I was having unexpected issues dropping this line on Android, although the docs say its deprecated.
    fb.authorize();
}

Will keep this ticket updated if/when this thing gets a formal fix.


Solution

  • This is my second answer on this question. I believe that my original answer offers some value to the conversation and that is why I am leaving it, but it still did not consistently solve the problem of the facebook authorization not working.

    The consistent solution turned out to be modifying the official Ti.Facebook module. I will submit a pull request for this change (1 line), but for now, you can get the working module here:

    Source

    Pre-built

    This consistently allows users to authorize by explicitly setting the login behavior to use the browser, rather than the native facebook app through fast app-switching. This is actually the intent of Facebook's developers.

    I was unable to determine what is causing it to fizzle when trying to use the native app to login - it should try the next option, which is the browser - but this works, and doesn't require a TiFacebookButton either.

    I hope it helps someone else!