I have upgraded Facebook SDK from 3.21.1 to 4.1 in an iOS app (already live).
I followed carefully the upgrade guide, and implemented the new methods for login. The code I used is the one provided in Facebook documentation.
But since the upgrade, each time I try to log in (device or simulator, webview or Facebook app), I can go through the login flow successfully, but when I fall back on my app, the login does not return any error but returns a FBSDKLoginManagerLoginResult "isCancelled".
As a workaround, I tried to implement app invites, which do not require login, but I'm stuck with a "Attempting to authenticate in FB" in the console... No luck here either.
So I guess it has something to do with the authentication fallback and the URL scheme in the info.plist, but I double checked there, and the data (which was working fine before the upgrade) is the same as the one indicated in Facebook documentation.
Anyone has any clue?? Thanks!
What I already checked:
Thanks to Dheeraj and its answer to a similar question, I found the error in my calls. I just made the stupidest error in Swift. In the unlikely event someone as dumb as I am read this, here are the 3 calls in Swift that you should add in your AppDelegate.swift. They are tested and working:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Do what you have to do but at the end, instead of 'return true', put :
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
}
I found the solution, the problem is that you don't complete the Facebook login process.
when you make facebook login request and then the user uses login via facebook app, The Facebook app opens again your application and call to
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool
on app delegate, to complete the process you need to pass facebook SDK the URL that came from Facebook that way:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options) == true {
}
Then you will see that the login request will return access token and won't be canceled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With