Description:
While testing a fix for TIMOB-23890, I noticed that the button for login required two presses before I was presented with the Facebook login. Sample code is here:
var fb = require("facebook");
// Facebook Stuff
fb.initialize();
var win = Ti.UI.createWindow();
var fbloginbutton = Ti.UI.createButton({
title: "Login with Facebook"
});
fbloginbutton.addEventListener("click", function() {
fb.authorize();
});
win.add(fbloginbutton);
var lbl = Ti.UI.createLabel({
color: "red",
text: fb.loggedIn
});
win.open();
Steps to reproduce:
1) Create a new classic mobile project
2) Attach the Facebook module
3) Paste the sample code into app.js
4) Install and launch
5) Press the "Login with Facebook" button
Result:
Nothing happens - Until you press the button again.
Expected Result:
The Facebook login process begins
[~hansknoechel] as you have mentioned to me before, is this related to another ticket?
Well, I guess it's because our
Ti.UI.Button
reacts different to a click-event than other UI-components do. It's more a general behavior than specific to our ti.facebook module. If you feel that we want to change this behavior, I'd do some native comparisons.I have been able to reproduce this on my app. Sometimes just tapping another Ti.Button on our login flow makes the Ti.Button for facebook login work. This makes fb.authorize() unusable for login (specially when you block the UI with a loader for preventing multiple taps on the fb login button). fb.authorize() is the only way to have custom facebook login buttons. Also, this is very hard (at least for us) to reproduce on the simulator as the button that calls the authorize method seems to always work, but on the device itself we've managed to reproduce it every time.
As a temp-fix/jerry-rig I've tried to add a setTimeout calling the fb.authorize() method again after 500 ms. This works for all the times in which I needed to tap the button again for login but sometimes when authorize() works at first call, it opens a second SFSafariViewController with the facebook login flow and mess up the login flow and callbacks on the app since I'm invoking authorize() 2 times. This is not a viable solution at all but may help you in debugging. Also I have noticed that after a successful facebook login on the app, the button always works normally if I logout and login again without killing the app. The issue returns if I logout and manually kill the app. For now we are unblocking the UI (removing a full screen loader after the user tap the Facebook login for the first time) so the user can tap again at his own will if the SFSafariViewController doesn't appear (which is far from optimal).
@Hans can we increase the priority of this issue? Is it being discussed for 6.0.0 ? Thanks.
Yes, I will investigate it in the upcoming sprint. I'm still wondering why that could be an issue. Is this also happening on iOS < 9? And how about older ti.facebook versions? I need as many environments as possible.
Just reproduced it, it's a valid issue! [~cng] Might even be considered for 5.5.1 *EDIT*: Found [this Stackoverflow post](http://stackoverflow.com/questions/39532132/blank-page-while-logging-in-with-facebook-sdk-on-ios-10) that has the exact same issue. So I guess the Safari-Dialog tries to pop up "too early" and since
fromViewController
isnil
in our case, it doesn't get called. [~ygbr] Can I send you a custom build that you verify? Guess I have something.@Hans sure, I can test it now. ps: I don't know why, but I can't mention anybody on appc Jira...
PR: https://github.com/appcelerator-modules/ti.facebook/pull/68 I will also cherry-pick the changes from [Kiat's PR](https://github.com/appcelerator-modules/ti.facebook/pull/67) for adjusted docs. [~ygbr] Please try [facebook-iphone-5.2.7.zip](https://www.dropbox.com/s/aj3diy7zxlx60z6/facebook-iphone-5.2.7.zip?dl=0), thanks!
CR and FT passed. PR merged. Can we have the back ports please.
PR (titanium_mobile): master: https://github.com/appcelerator/titanium_mobile/pull/8390 6_0_X: https://github.com/appcelerator/titanium_mobile/pull/8391 5_5_X: https://github.com/appcelerator/titanium_mobile/pull/8392
Verified the fix. The button listener now responds after the first click for facebook login. Closing. Environment: Appc Studio : 4.8.0.201609191928 Ti SDK : 6.1.0.v20160922115612, 6.0.0.v20160922115636, 5.5.1.v20160921190109 Ti CLI : 5.0.9 Alloy : 1.9.1 MAC El Capitan : 10.11.6 Appc NPM : 4.2.7 Appc CLI : 5.5.0 Node: 4.4.4 Iphone 6 : IOS 10 Iphone simulator 7 plus : IOS 10 Iphone 6 : IOS 9.3.5 Facebook module : 5.2.7