facebook / facebook-ios-sdk

Used to integrate the Facebook Platform with your iOS & tvOS apps.
https://developers.facebook.com/docs/ios
Other
7.75k stars 3.51k forks source link

Facebook Login Not Working On The First Login #2439

Open aemreb opened 3 weeks ago

aemreb commented 3 weeks ago

Checklist before submitting a bug report

Xcode version

15.4

Facebook iOS SDK version

17.0.1

Dependency Manager

SPM

SDK Framework

Core

Goals

I want the Facebook app to redirect back to my app after login process is initialized while logged out on the Facebook app.

Expected results

I want the Facebook app to redirect back to my app.

Actual results

Facebook app stays in place, directs me to the home page.

Steps to reproduce

-Log out of Facebook on web and the mobile app -Log in using the Facebook Login button placed inside the app -See that the redirect mechanism back to the main app is broken, but it works fine if the user is already logged in on the FB app

Code samples & details

// INSERT YOUR CODE HERE
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        _ = ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
        return true
    }

    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
        guard url.scheme != nil else { return false }
        if url.scheme == "fbxxxxxx" { //Facebook id
            return ApplicationDelegate.shared.application(app, open: url, options: options)
        }

        if url.host == "authorize" {
            Adjust.appWillOpen(url)
            return ApplicationDelegate.shared.application(app, open: url, options: options)
        }
        return true
    }

// ---------

        let facebookLoginButton = FBLoginButton()
        facebookLoginButton.delegate = self
        facebookLoginButton.permissions = ["public_profile", "email"]
        facebookLoginButton.sendActions(for: .touchUpInside)
        facebookSignInCompleted = completion

// ----------
sylvia-tencent-wmt commented 2 weeks ago

I encountered the same issue too.

  1. First time login will display webview (I'm using iPad, not sure if this behavior was correct).
  2. After entered the login credentials it login successfully, but it stayed in the Facebook home page, instead of redirecting to my app.
  3. I have to cancel to dismiss the webview, subsequent login was successful and was able to redirect to my app.

The above issue can be reproduced by logout from my app, and clear the Safari web history.

Facebook iOS SDK version: 17.0.0 Device version: iOS 17