facebook login trapped in a loop if open in facebook app

2.2k Views Asked by At

I'm implementing Facebook login in my app. it works fine if a user doesn't have the Facebook App, but it fails when the user has Facebook App. Because when logging in, it promotes to use the app to do login. And once signed in within the Facebook App, it comes back and stuck at the signin screen.

see the following screen recording:

https://flair-inventory.s3-us-west-2.amazonaws.com/RPReplay_Final1591237513.MP4

The following project can reproduce the same issue. build and install this app on a device, and at the same time, install facebook app on the same device.

The following app can reproduce this issue:

https://github.com/LeeKahSeng/SwiftSenpai-FB-Integration-Demo

2

There are 2 best solutions below

0
Papon Smc On

If you set step login facebook is correct you should check Appdelegate below function maybe in your code return false.

try follow this it's work for me in same case your video.

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

Credit to this post:

In my case, after adding the extra code of the SceneDelegate as per FB documentation, I also needed to add the .onOpenURL { ... } code on the LoadingView() called in my MotherView like this example:

var body: some Scene {
    WindowGroup {
        LoadingView()
            .onOpenURL { (url) in
                ApplicationDelegate.shared.application(
                    UIApplication.shared,
                    open: url,
                    sourceApplication: nil,
                    annotation: [UIApplication.OpenURLOptionsKey.annotation]
                )
            }
    }
}