Facebook-ios-sdk: Cannot login with Facebook on iOS 13

Created on 13 Sep 2019  路  7Comments  路  Source: facebook/facebook-ios-sdk

Checklist

Environment

  • Xcode Version: Version 11.0 (11A419c)
  • Swift Version: 5.0 (if issue is Swift related)
  • Installation Platform & Verison: [Cocoapods] version 5.5.0

Goals

I want users to be able to login to facebook on our app from a webview in iOS 13.

Expected Results

I expect a webview to open after users click on 'continue' when he is asked to sign in with facebook where they can log in with facebook on ios13.

Actual Results

Nothing happens after i click the continue button. No popup or webview opens

Steps to Reproduce

Call the facebook login functionality with LoginManager().logIn(permissions: permissions, from: presenter) { (result, error)

Code Samples & Details

import FBSDKLoginKit

class FacebookService: FacebookServiceProtocol {
    func authorize(permissions: [String], success: @escaping (String?) -> Void, failure: @escaping () -> Void) {
        guard let presenter = UIApplication.shared.rootViewController?.navController?.presentedViewController else {
            failure()
            return
        }

        LoginManager().logIn(permissions: permissions, from: presenter) { (result, error) in
            guard error == nil,
                let result = result, !result.isCancelled,
                let tokenString = result.token?.tokenString else {
                    LoginManager().logOut()
                    failure()

                    return
            }

            success(tokenString)
        }
    }
}

Most helpful comment

Not sure if the earlier issue is the same but my new apps broke with iOS 13 projects due to the scene delegate and the fix was pretty simple as per the following post https://github.com/facebook/facebook-ios-sdk/issues/1067#issuecomment-559629930:

See my post here for the solution to this - its pretty simple: https://github.com/facebook/facebook-ios-sdk/issues/1067#issuecomment-559629930

With the latest SDK, this does work fine if you are at NOT using SceneDelegate.

If you are using sceneDelegate the the following AppDelegate method is not called and therefore the login cannot be handled.

func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    let handled = ApplicationDelegate.shared.application(
        application,
        open: url,
        sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
        annotation: options[UIApplication.OpenURLOptionsKey.annotation])
    return handled
}

This is because, this method is (understandably) deferred to the following method in the SceneDelegate:

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    ...
}

The solution which I can confirm as working for iOS 13 applications implementing a SceneDelegate is:

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    guard let url = URLContexts.first?.url else {
        return
    }
    let _ = ApplicationDelegate.shared.application(
        UIApplication.shared,
        open: url,
        sourceApplication: nil,
        annotation: [UIApplication.OpenURLOptionsKey.annotation])        
}

All 7 comments

Hi @Meilu , did you create the project via Xcode 11? If so, most likely this is duplicate to https://github.com/facebook/facebook-objc-sdk/issues/1043, which we'll fix in next release this week.

We've released 5.6.0 with support for multi-window apps, please let us know if you could still see this issue.

This bug still appears for me even when I updated to 5.6.0

Still even in 5.7.0. Please reopen this is quite urgent.

I am facing same issue in 5.7.0. Please reopen it.

Not sure if the earlier issue is the same but my new apps broke with iOS 13 projects due to the scene delegate and the fix was pretty simple as per the following post https://github.com/facebook/facebook-ios-sdk/issues/1067#issuecomment-559629930:

See my post here for the solution to this - its pretty simple: https://github.com/facebook/facebook-ios-sdk/issues/1067#issuecomment-559629930

With the latest SDK, this does work fine if you are at NOT using SceneDelegate.

If you are using sceneDelegate the the following AppDelegate method is not called and therefore the login cannot be handled.

func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    let handled = ApplicationDelegate.shared.application(
        application,
        open: url,
        sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
        annotation: options[UIApplication.OpenURLOptionsKey.annotation])
    return handled
}

This is because, this method is (understandably) deferred to the following method in the SceneDelegate:

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    ...
}

The solution which I can confirm as working for iOS 13 applications implementing a SceneDelegate is:

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    guard let url = URLContexts.first?.url else {
        return
    }
    let _ = ApplicationDelegate.shared.application(
        UIApplication.shared,
        open: url,
        sourceApplication: nil,
        annotation: [UIApplication.OpenURLOptionsKey.annotation])        
}

Hello Everybody.

I have got new issues today FB login with below IOS 13 if i want to login above IOS 13 then I got this message.

Simulator Screen Shot - iPhone 11 Pro Max - 2020-01-29 at 18 03 58

This project had created in Xcode 9.

And I have not used Scene Delegate in this.

Thanks

Was this page helpful?
0 / 5 - 0 ratings