[TIMOB-23890] iOS10: Facebook Login is not working
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-09-13T00:14:55.000+0000 |
Affected Version/s | Release 5.4.0, Release 5.5.0 |
Fix Version/s | Release 5.5.0 |
Components | iOS |
Labels | facebook, facebookSDK, ios, ios10, ti.facebook, xcode8 |
Reporter | Ygor Lemos |
Assignee | Hans Knöchel |
Created | 2016-09-09T23:42:06.000+0000 |
Updated | 2016-11-17T08:16:44.000+0000 |
Description
Facebook login using the latest FB Modules is not working anymore on devices running iOS 10.
We have catch this behavior on our production published app running the Facebook Module (5.2.0) and Ti SDK 5.3.0.
We have tested this behavior on Ti SDK 5.2.0.GA up to 5.5.0 RC and all present the same behavior.
*Steps to Reproduce*
* Use a button for Facebook login (using the fb.authorize method).
* The button opens the SafariView with the Facebook App Authorization site.
* Tap OK button.
* The SafariView gets a blank page and doesn't get dismissed.
* If you tap the DONE button, the view is dismissed but the is not logged in.
*Expected*
Normal FB login flow where you tap the OK button on the SafariViewController opened by the Facebook module, the SafariViewController gets dismissed, the login event is fired with the user logged in.
*Follows a very simple app using the Facebook Module displaying this issue.*
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.add(lbl);
fb.addEventListener("login", function() {
console.log("fb-event-login: " + fb.loggedIn);
console.log("accessToken: " + fb.accessToken);
console.log("fbuid: " + fb.uid);
lbl.setText(fb.loggedIn);
});
fb.addEventListener("logout", function() {
console.log("fb-event-logout: " + fb.loggedIn);
console.log("accessToken: " + fb.accessToken);
lbl.setText(fb.loggedIn);
});
console.log("fb-boot-status: " + fb.loggedIn);
console.log("fb-boot-accessToken: " + fb.accessToken);
win.open();
Please remember to setup the proper Facebook App ID parameters on tiapp.xml on the iOS section together with LSApplicationQueriesSchemes and NSAppTransportSecurity as per Facebook Ti module instructions.
This is critical since iOS 10 final is to be released next week and this completely breaks Facebook login.
More Info: * Using the Module Login Button (using createLoginButton) presents the same behavior. * If you tap to open the Link In Safari, it opens in safari and when you tap OK it goes back to the app and crashes ([ERROR] The application has crashed with an uncaught exception 'NSInvalidArgumentException'. [ERROR] Reason: [ERROR] *** setObjectForKey: object cannot be nil (key: error)) * We have tried to use the latest version of the ti.facebook module on github (iOS-5.2.4 release) and it does not solve this problem. * Facebook has released the 4.15.1 version of their SDK which makes some updates related to XCode 8 and iOS 10 (Ti.Facebook module seems to use 4.14.0 on the latest Github Version)
Other apps that use the same native login flow on iOS (opens SFSafariViewController with Facebook login inside the app itself) are working fine after updating to iOS 10. Our app which the current iOS Published version is compiled with Facebook Module (5.2.0) and Ti SDK 5.3.0 is not. On all our tests running against iOS 9 both on devices as in the simulator, the login behaves normally.
other devs are experiencing this problem as well: http://stackoverflow.com/questions/39297781/facebook-login-doesnt-works-on-ios-10-titanium-sdk-5-3-1-ga-and-5-5-0-beta/39422401#39422401
I have tried to compile the current ti.facebook module source replacing the Facebook SDK frameworks with the ones available on their latest SDK (4.15.1). The module works fine but shows the same behavior presenting a blank screen after tapping OK and not returning to the app. Closing the safari view controller manually returns to the app and fires the login event as "cancelled" and it doesn't login at all.
Hey [~ygbr], I'm here! Before I dig into the issue, I would like to clear the following quote: {quote} We have catch this behavior on our production published app running the Facebook Module (5.2.0) and Ti SDK 5.3.0. {quote} How can you catch the error-behavior in a production app when a) iOS 10 need to be built with Xcode 8 which is not able to have apps in the store, yet and b) you are using Ti SDK 5.3.0 for that which does not support iOS 10 builds, yet. Thanks!
Let's go: - This seems to happen on the native side as well (https://forums.developer.apple.com/thread/50332 + http://stackoverflow.com/questions/38689631/how-to-use-facebook-ios-sdk-on-ios-10) - Make sure you have included all iOS required query schemes (if that works, let me know and I'll update the docs anyway):
- Enable keychain-sharing in your entitlements with your app-id from the tiapp.xml (if that works, we need to update the docs as well):
So summary: I don't think it's the Facebook module itself, but the way we need to implement it for iOS 10. I will see if Facebook has a specific SDK release for iOS 10 so we can include that as well. Thanks!
PR (ti.facebook): https://github.com/appcelerator-modules/ti.facebook/pull/63 [~ygbr] Please try the ti.facebook version 5.2.5 that is attached to the PR, as well as the above hints. Pretty sure that will work. Thanks!
@Hans clearing out your questions: bq. How can you catch the error-behavior in a production app when a) iOS 10 need to be built with Xcode 8 which is not able to have apps in the store, yet and b) you are using Ti SDK 5.3.0 for that which does not support iOS 10 builds, yet. Thanks! We have installed the current version of our production app available in the iOS App Store ( compiled with Facebook Module (5.2.0), Xcode 7 and Ti SDK 5.3.0) and the facebook login simply stopped working after updating to iOS 10 GM. (Tested on iPhone 5S, 6, and 6S Plus). It worked flawlessly on iOS 9. Just to be clear, just updating to iOS 10 completely breaks Facebook Login on previously published Ti apps, which doesn't happens with other (non-ti) apps that were also compiled with previous versions of Xcode and FB SDKs. We have tested a plethora of other iOS apps that uses Facebook login and they are working just fine after updating to to iOS 10. All titanium apps that we control are having this login failure on iOS 10. I will try the keychain and adding the extra LSApplicationQueriesSchemes (even though Facebook SDK explicitly says to remove the extra ones in the latest SDK version) and report back here soon. Thanks.
Thanks for the feedback! The entitlements are not necessary anymore, since the newer version of the Facebook SDK sets them for you. I am still able to reproduce it and need some more testing right now. Will keep you updated.
@Hans Thanks for the feedback. As a side note I have tried all the steps you mentioned and the FB Module attached to your PR (5.2.5) but still get the same effects (yesterday I have tried to update the FB SDK frameworks on the module myself too, but I got the same results). I also have tried to test it with run-on-main-thread on and off and the with the new jscore framework enabled but the problem persists in all cases.
Ok, found the problem. In the Titanium SDK core, we have the following application delegate to handle url-opens:
When using the Facebook-SDK, the following thing is recommended:
and for some reason, it never made problems before, but now it does. So we need to find a way to hook into that delegate from the module.
Ok, I have something working (although I'm not sure it's the best way to do it, yet): We need an SDK-core PR to send out a notification when the above delegate is called by the system. In the module, we hook into that notification like we do with other (system- and SDK-side notifications). Inside there, we call the Facebook-delegate and the callback in
authorize
that has not been triggered gets triggered. Works with both active and inactive sessions. Anyway, it requires a lot of testing to ensure everything in the session- and accesstoken-handling still works. PR's: - ti.facebook: https://github.com/appcelerator-modules/ti.facebook/pull/63 - titanium_mobile (master): https://github.com/appcelerator/titanium_mobile/pull/8346 - titanium_mobile (6_0_X): https://github.com/appcelerator/titanium_mobile/pull/8352 - titanium_mobile (5_5_X): https://github.com/appcelerator/titanium_mobile/pull/8351 I will do the 6_0_X and 5_5_X backports as soon as [~ygbr] and [~cng] can confirm the fix. I updated the prepackaged version in the ti.facebook PR as well. Fingers crossed!Hi Hans, I have tested using your updated module PR and your pull on Ti master (6.1.0) and now when I tap on the OK button inside the FB Login SafariViewController I get the following crash:
Mhh, it looks like in [this line](https://github.com/hansemannn/ti.facebook/blob/85ec3e4307bf8375f0450d104ed0e8c6a804d7cd/ios/Classes/FacebookModule.m#L870) the
errorString
is nil. Very weird. I just pushed another commit to optimize the delegate handling, please build the module yourself this time to speed-up the debugging, thanks!.Hi Hans, I have downloaded the latest version from your PR and build it myself. Still getting the following error after I tap OK on the SafariViewController
I have actually created a very simple app just for testing this issue and also created the application on Facebook, so everything is wired app correctly. Does it help you if I provide you with this testing source??? (if you want I can also make you an admin or tester of the app on facebook dev platform so you can actually login and run the app or I can create test users and provide the test logins here). This way you can just drop the updated module on every change and I think it would make debugging faster.
Did you use a precompiled master? Since the PR is not merged, yet, you need to compile a custom 6.1.0 from the above PR. Let me package it for you and give it to test, so we can speed-up the process. *EDIT*: Please download and unzip [this file](https://www.dropbox.com/s/kuip20k1xjcjvn3/5.5.0.zip?dl=0) to
~/Library/Application Support/Titanium/mobilesdk/osx/5.5.0
and make sure to change the SDK-version to that one. It is the latest 5.5.0 build including the fixes from the above PR (in TiBase.h/m and TiApp.m).Hi Hans, I couldn't use the precompiled master because the ones on build.appcelerator were all 2 days old, so I went and checked-out the entire master pointed to your commit: 28ad30f12bb28c464b1f6e03da10b37463b1ace6 (which is the last one on your pull request to titanium_mobile) I will try with the version you packaged above and report back soon.
I just downloaded your pre-packaged 5.5.0 and used that to make a clean build of the app. I have also used the ti.facebook that I built module from the latest commit on your PR (f0ade97). Unfortunately the app still gives the same crash after I tap OK on the SafariController. On a side note, previously if I tapped the bottom-right button on the SafariController to open the fb login site on Safari externally and perform the authentication on Safari, it did get back to the app and the login happened normally. Now in this version it crashes too.
Also, I have observed that if we make the login using the module's button (fb.createLoginButton) it doesn't crash when returning to the app, different behavior of calling the authorize() method directly. That said, it returns to the app without a crash but doesn't login the user since all state variables are nil/undefined.
Added an additional commit to fire a
Ti.App.iOS.handleurl
event to get notified about handled URL's. Relates to two other tickets, so I've put it here to link it.More PRs!: 6_0_X: https://github.com/appcelerator/titanium_mobile/pull/8358 5_5_X: https://github.com/appcelerator/titanium_mobile/pull/8357 master: https://github.com/appcelerator/titanium_mobile/pull/8356 facebook module: https://github.com/appcelerator-modules/ti.facebook/pull/64
Steps to test
Scenario A: Use the case above. It will fail to log in without crashing. Scenario B: Using the same case, follow these instructions to include a appname.entitlements inplatform/ios
: {quote} **Using Facebook module with iOS 10 and Xcode 8** To log in using facebook, we now have to include an entitlements file that enables Keychain Sharing Capabilities. To do so, create a/platform/ios/<appname>.entitlements
file with this content {quote}@Chee 1. Do we really have to create the entitlements file on /platform/ios or can we add
[~ygbr] 1. It needs to be the entitlements-file, because the Info.plist is not the .entitlements file (the entitlements are used to manage app capabilities, the Info.plist to manage app settings) 2. I need to look-up the folder-structure, but it's similar to where you save localized app-titles as well. Reading your comment, you probably copied the proposed entitlements to your tiapp instead of a new file? That would solve the last mystery, why it worked for me but didn't for you.
@Hans I can confirm that after adding the entitlements to /platform/ios/fblogintest.entitlements file with keychain-access-groups it stopped crashing and facebook login now works both with the authorize() as with the facebook login button. Thanks Hans!!!
Please note that you need $(AppIdentifierPrefix) in the entitlements file in order to run on device.
Verified with Ygor's sample that the workflow was successful. Got a red "1" indicating login. Created a new Facebook developer entry and set plist as required. Initially had issues with entitlements on the provision installing to device, but [~cng] has a solution there we should get tomorrow. Also verified the following as additional test.
All performed with: Xcode: 8.0 beta 6 (8S201h) iOS: 10.0.1 (14A403) Appc CLI Core: 5.5.0-6 Appc CLI NPM: 4.2.7 Appcelerator Studio: 4.7.1.201609100950 Titanium SDK: 5.5.0.v20160912200427 Facebook module: 5.2.5
New PRs with doc updates here: 5_5_X: https://github.com/appcelerator/titanium_mobile/pull/8362 6_0_X: https://github.com/appcelerator/titanium_mobile/pull/8363 master: https://github.com/appcelerator/titanium_mobile/pull/8364 facebook PR: https://github.com/appcelerator-modules/ti.facebook/pull/65
Follow-up ticket to support Titanium SDK < 5.5.0: MOD-2297
Verified fixed with: NPM Version: 2.15.1 Node Version: 4.4.3 Mac OS: 10.11.2 Appc CLI: 5.5.0 Appc CLI NPM: 4.2.7 Titanium SDK version: 5.5.0.GA Appcelerator Studio, build: 4.7.1.201609100950 Xcode 8.0 GM I used the sample code attached as well as the one mentioned in my previous comment. I noticed that the log in requires two button pushes before logging in, and will write a separate ticket for that and link here.
Please reopen this issue as the problem still exists.
[~bfreid] can you please provide more information of the problem you have and share with us the environment you are using? Make sure it's Facebook module 5.2.6. Is it failing for only iOS10 or everything? Thanks.
I have just verified with the development team that this issue still exists and is becoming very visible with more and more people upgrading to IOS10.
@Chee: I've confirmed that we are using the Facebook module 5.2.6
[~bfreid] can you describe the scenario again? You meant the first attempt will cause the app to hang and not Facebook right? Is this happening on simulator? On simulator you have to provide an appname.entitlements file to platform/ios as instructed on the readme and docs for it to run. It'll be helpful if you can provide us a reproducible sample code so that we can isolate the problem you are facing.
@Chee we are having same issues on 5.2.7 as we had on 5.2.6. This is not done on a simulator, it is on a live app. the first time you install the application it works, from there on every time after will open login page and go back to the app and show it's loading till the login is prompted a 2nd time. the only way to get it work the first time thereafter is to uninstall/reinstall the app or reboot the device.
Hello Brian Freid. By my side it is working good. But I had to execute the logout method before executing the authorize method. Please try this: fb.initialize(); fb.logout(); fb.authorize(); Thanks, and best, Antonio.
Francisco, Thank you for the recommendation, unfortunately our login process is more complex and won't work as you suggested. Because of the problems that Appcelerator is having with logging, we are unable to trouble shoot the problem in more detail. We've tried several different recommendations and unfortunately none of them have been successful.
Can someone provide an update on the status of this issue?
[~bfreid] We didn't hear any open issue since TIMOB-23904 was fixed. If you still have issues with ti.facebook 5.2.7, please provide a test-case that is reproducible and we can take a look. Thanks!
@Hans Knoechel we are having same issues on 5.2.7 as we had on 5.2.6. This is not done on a simulator, it is on a live app. the first time you install the application it works, from there on every time after will open login page and go back to the app and show it's loading till the login is prompted a 2nd time. the only way to get it work the first time thereafter is to uninstall/reinstall the app or reboot the device.
[~bfreid] Once again, we cannot reproduce your issue without a valid demo-code to debug. Please provide one (isolated, runnable through a single app.js if possible) and we can speed-up the review of it. Thanks!
Hey [~bfreid], very happy to hear that, thank you!
@Brian Freid: We have a very similar problem with a URL scheme. What was the fix for you?
What was the issue?
Hi guys, I was still facing the error with the module's facebook button even with module version 5.2.7 . I replaced it with a normal button and it worked.
[~hini] It's confirmed to be working so it must be something with your environment. Make sure to follow the guide in the [Ti.Facebook docs](http://docs.appcelerator.com/platform/latest/#!/api/Modules.Facebook) to migrate and ensure to use at least 5.5.1.GA (both CLI and SDK) with Xcode 8 and iOS 10. Thanks!
Thanks for replying Hans. I see from the thread that what was tested is using a normal button, not the module's facebook login buggon. I can confirm that using a normal button worked fine, but my initial code which uses the module's login button still causes the same behavior This works:
but this shows the blank safari screen and a warining in the logs: "Warning :-Presenting view controllers on detached view controllers is discouraged:"
Thanks last post worked for me too!