简体   繁体   中英

Facebook login stuck

I am trying to implement Facebook login into my app and I'm closely following the documentation.

  1. I set up the Info.plist file
  2. I also set up the AppDelegate

In the viewDidLoad method I have the folling code:

let loginButton = LoginButton(readPermissions: [ .publicProfile ])
loginButton.center = view.center
loginButton.delegate = self
view.addSubview(loginButton)

The viewController conforms to the delegate:

extension FacebookLoginViewController: LoginButtonDelegate {
        func loginButtonDidCompleteLogin(_ loginButton: LoginButton, result: LoginResult) {
            switch result {
            case .cancelled:
                print("User cancelled login")
            case .failed(let error):
                print("Failed: \(error)")
            case .success:
                print("Successful login")
            }
        }

        func loginButtonDidLogOut(_ loginButton: LoginButton) { print("Logged out") }
}

When I click the login button an in-app browser window comes up and it asks whether I want to login with the Facebook app or the browser. screenshot of selection view

If I select the browser then I need to enter my username and password and it works .

If I select the app and go through the authentication process and come back to my app it is like nothing happened . The prompt to select the Facebook app or the browser is still there. And the request didn't fail or succeed or anything. It doesn't even call the delegate method.

Is there something else I need to do for the Authentication to work through the app?

The solution is simple. Straight from Facebook iOS team: All you need to do is to add this function in your AppDelegate file.

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM