Facebook login error (always isCancelled) after upgrading to SDK 4.1

I updated the Facebook SDK from 3.21.1 to 4.1 in the iOS app (already live).

I carefully followed the upgrade guide and implemented new login methods. The code I used is the one given in the Facebook documentation.

But since the update, every time I try to log into the system (device or simulator, web viewer application or Facebook), I can successfully go through the login flow, but when I return to my application, the login does not return any but returns FBSDKLoginManagerLoginResult "isCancelled".

As a workaround, I tried to implement applications that do not require logging in, but I was stuck in the "Attempting Authentication in FB" console ... No luck here.

So, I think this is due to fallback authentication and the URL scheme in info.plist, but I double checked there and the data (which worked fine before the update) was the same as stated in the Facebook documentation.

Does anyone have a clue? Thanks!

What I already checked:

  • I did not change info.plist, which is already configured to use the Facebook SDK and worked fine before updating.
  • The user account I use to log in also worked fine before this update.
  • I do not have currentAccessToken before or after the login process.
+6
source share
4 answers

Thanks to Dheeraj and his answer to a similar question , I found an error in my calls. I just made the dumbest mistake in Swift. In the unlikely event that someone is as dumb as I read this, here are 3 calls to Swift that you should add to your AppDelegate.swift. They are tested and work:

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() } 
+8
source

Thumbs up your winter. And thanks to Dheeraj bhai. Here I am just updating the answer for Swift 3.1.

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) } func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application(application, open: url as URL!, sourceApplication: sourceApplication, annotation: annotation) } func applicationDidBecomeActive(application: UIApplication) { FBSDKAppEvents.activateApp() } 

And yes, do not forget to put:

 import FBSDKCoreKit 

in the App Delegate.

0
source

Another reason to call FBSDKLoginManagerLoginResult always return isCancelled : if the application (in development) requests certain permissions, the user is not a registered developer for this application, and FaceBook has not yet approved the application for these permissions, it will always return isCancelled .

0
source

I found a solution, the problem is that you did not complete the Facebook login process.

When you make a login request to Facebook, and then the user uses the login through the Facebook application, the Facebook application opens your application again and calls

 func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool 

in the application delegate, to complete the process, you need to pass the Facebook SDK the URL obtained from Facebook as follows:

  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 entry request will return an access token and will not be canceled.

0
source

All Articles