plugins icon indicating copy to clipboard operation
plugins copied to clipboard

Facebook login not closing (delegate issue?)

Open Oshr1 opened this issue 3 years ago • 8 comments

Facebook login + firebasr not working properly, FB app opens and after successfully submitting Facebook login the app stays open and not returning to my app

Oshr1 avatar Oct 17 '22 21:10 Oshr1

this is what I experience now too

souriscloud avatar Feb 10 '23 21:02 souriscloud

me too :/ did you guys find a solution for this?

res0 avatar Dec 05 '23 09:12 res0

Title refers to a delegate, so I guess it's an iOS-specific problem? Does anyone experience the same problem on android?

CatchABus avatar Dec 05 '23 09:12 CatchABus

@CatchABus yeah it's iOS specific, it works on iOS Simulator though (as there's no FB app), but it doesn't work on real iOS device where the Facebook app is installed. It opens a window with a button which says Log In With the Facebook App, which when clicked opens the Facebook App where I can tap on Log in. Then it goes back to that window without closing and resolving.

res0 avatar Dec 05 '23 11:12 res0

I am also having this problem. It's like the NSCFacebookUIAppDelegateExt isn't being used.

I tested this with the new addDelegateHandler and I can see the events when the user returns from the Facebook app.

const Application = require("@nativescript/core").Application;

if (Application.ios) {
    Application.ios.addDelegateHandler('applicationOpenURLOptions', (app, url, options) => {
        console.log("HANDLE RETURN FROM FACEBOOK.");
    });
 }

No idea how to link this up though...

LewisSmallwood avatar Feb 23 '24 11:02 LewisSmallwood

I did some more digging, and have found a fix that utilizes the new addDelegateHandler added in v8.6.0.

It would be useful if this could be merged into the plugin's init method so we don't have to add this too...

But to get it working, just add this code after the LoginManager.init(); call:

if (Application.ios) {
    // Hook the launch event up with the Facebook SDK delegate.
    Application.ios.addDelegateHandler("applicationDidFinishLaunchingWithOptions", (app, launchOptions) => {
        return FBSDKApplicationDelegate.sharedInstance.applicationDidFinishLaunchingWithOptions(app, launchOptions);
    });

    // Hook up the application launch from URL.
    Application.ios.addDelegateHandler('applicationOpenURLOptions', (app, url, options) => {
        if (url && url.scheme.startsWith("fb")) {
            FBSDKApplicationDelegate.sharedInstance.applicationOpenURLSourceApplicationAnnotation(app, url, options.valueForKey(UIApplicationOpenURLOptionsSourceApplicationKey), options.valueForKey(UIApplicationOpenURLOptionsAnnotationKey));
        }
    });
}

LewisSmallwood avatar Feb 23 '24 12:02 LewisSmallwood

@LewisSmallwood thanks for looking at this :) I tried it now, however I get this error when I get back from the Facebook app: TypeError: FBSDKApplicationDelegate.sharedInstance.applicationOpenURLSourceApplicationAnnotation is not a function Do you know what can be the problem on my side?

res0 avatar Feb 26 '24 21:02 res0

@LewisSmallwood do you know if you have development target set to 13+? I'm reading this on Facebook SDK docs(https://developers.facebook.com/docs/facebook-login/ios/)

iOS 13 moved opening URL functionality to the SceneDelegate. If you are using iOS 13, add the following method to your SceneDelegate so that operations like logging in or sharing function as intended

So I'm curious if that could be the problem for me if I have target set to 13?

res0 avatar Mar 12 '24 11:03 res0