Facebook-ios-sdk: Facebook Login doesn't doesn't dismiss Login Dialog after login

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

Checklist

Environment

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

Expected Results

  1. Click on FB login button
  2. FB login web view should pop up
  3. if FB app is installed then webView should show message to open fb app
  4. after successful login SDK should return to my app

Actual Results

Facebook Login popup doesn't dismiss after completing successful login

What actually happened? Can you provide a stack trace?

No error is shown or app doesn't crash but console display following warning

Can't end BackgroundTask: no background task exists identifier 5 (0x5), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.

Steps to Reproduce

  1. Click on FB login button
  2. FB login web view should pop up
  3. if FB app is installed then webView should show message to open fb app
  4. after successful login popup doesn't get dismissed

Code Samples & Details

Note: Remember to format your code for readability:

AppDelegate.swift

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 {
            return ApplicationDelegate.shared.application(app, open: url, options: options)
    }

ViewController.swift

override func viewDidLoad() {
        super.viewDidLoad()


        let loginButton = FBLoginButton()
        loginButton.permissions = ["public_profile", "email"]
        loginButton.center = view.center
        view.addSubview(loginButton)
    }



Most helpful comment

@Akshay-bcat @MattBlack01 Adding the following to SceneDelegate.swift should resolve the issue:

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        if let openURLContext = URLContexts.first {
            ApplicationDelegate.shared.application(UIApplication.shared,
                                                   open: openURLContext.url,
                                                   sourceApplication: openURLContext.options.sourceApplication,
                                                   annotation: openURLContext.options.annotation)
        }
    }

All 7 comments

https://github.com/facebook/facebook-ios-sdk/issues/1074#issuecomment-551619270

Hi

After we upgraded our iOS to 13.x version, changed FBlogin pods and login codes like in the link above. I had this problem too and it has resolved with that codes.

I wish it will help you.

I've exactly the same issue. Any updates?

If you start a new project and have the SceneKit integration in it.

To solve the issue

  1. Remove all the SceneKit references in AppDelegate.swift and Info.plist files.
  2. Add var window: UIWindow? to AppDelegate.swift

@Akshay-bcat Does your app use SceneKit, and if so, does the above fix work for you?

After upgraded my iPhone to iOS 13.3 the problem solved.

I am having the same issue.
I am not using SceneKit.

SwiftUI
Xcode 11.3
iOS 13.3

Interestingly the view dismisses as expected when I login in using the email / phone number option but not if I go through the app.

@Akshay-bcat @MattBlack01 Adding the following to SceneDelegate.swift should resolve the issue:

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        if let openURLContext = URLContexts.first {
            ApplicationDelegate.shared.application(UIApplication.shared,
                                                   open: openURLContext.url,
                                                   sourceApplication: openURLContext.options.sourceApplication,
                                                   annotation: openURLContext.options.annotation)
        }
    }
Was this page helpful?
0 / 5 - 0 ratings