facebookarchive / react-native-fbsdk

A React Native wrapper around the Facebook SDKs for Android and iOS. Provides access to Facebook login, sharing, graph requests, app events etc.
https://developers.facebook.com/docs/react-native
Other
2.99k stars 910 forks source link

login failed at iOS using facebook app login without safari web facebook loggined. #714

Open stevesaygoodbuycom opened 4 years ago

stevesaygoodbuycom commented 4 years ago

It's good working when safari web loggined in facebook.

but didn't login safari web and login with facebook app

throw isCancelled true.

anybody help me?


    LoginManager.logInWithPermissions(["public_profile", "email"]).then(
        (result) => {
            if (result.isCancelled) {
                Alert.alert('0. cancelled!!!!!!!!!!!!!!!!!!!');
                console.log("Login cancelled");
                LoginManager.logInWithPermissions(["public_profile"]).then(
                    (result) => {
                        if (result.isCancelled) {
                            Alert.alert('5555555. cancelled!!!!!!!!!!!!!!!!!!!');
                            console.log("Login cancelled");
                        } else {
                            Alert.alert('5555555. onFacebookClicked go');
                            getFacebookInfo()
                        }
                    },
                    function (error) {
                        Alert.alert('33333. Login fail with error->' + error.message);
                        console.log("Login fail with error: " + error);
                    }
                );
            } else {
                Alert.alert('1. onFacebookClicked go');
                getFacebookInfo()
            }
        },
        function (error) {
            Alert.alert('0. Login fail with error->' + error.message);
            console.log("Login fail with error: " + error);
            LoginManager.logInWithPermissions(["public_profile"]).then(
                (result) => {
                    if (result.isCancelled) {
                        Alert.alert('1. cancelled!!!!!!!!!!!!!!!!!!!');
                        console.log("Login cancelled");
                    } else {
                        Alert.alert('222222. onFacebookClicked go');
                        getFacebookInfo()
                    }
                },
                function (error) {
                    Alert.alert('33333. Login fail with error->' + error.message);
                    console.log("Login fail with error: " + error);
                }
            );
        }
    );
};
stevesaygoodbuycom commented 4 years ago

test conditions

  1. facebook app install at phone.
  2. facebook logout at safari web.
  3. run login using react-native-fbsdk

-> failed ( cacelled return )

I think when use facebook app login, safari web didn't login.. so facebook sdk return cacelled..

If loggined safari facebook web, it passed else always cacelled return.

anybody help me~

tonydung2011 commented 4 years ago

I encounter the same issue today in both the release and development environment. This is not the first time I encounter an issue like this. Here is my checklist

torcoste commented 4 years ago

Check your AppDelegate.m file.

This code:

if ([[FBSDKApplicationDelegate sharedInstance] application:application
                                                              openURL:url
                                                    sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                                                            annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
        ]) {
     return YES;
   }

should be above this code:

  if ([RCTLinkingManager application:application openURL:url options:options]) {
    return YES;
  }

Otherwise, RCTLinkingManager will process the link instead of FBSDK

mralj commented 4 years ago

Check your AppDelegate.m file.

This code:

if ([[FBSDKApplicationDelegate sharedInstance] application:application
                                                              openURL:url
                                                    sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                                                            annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
        ]) {
     return YES;
   }

should be above this code:

  if ([RCTLinkingManager application:application openURL:url options:options]) {
    return YES;
  }

Otherwise, RCTLinkingManager will process the link instead of FBSDK

Thanks a lot, this helped us, we have had similar issue:

Everything works fine unless you have installed Facebook app on your phone (which I guess most of the people do), FB Login Flow is broken, meaning

  1. I tap on "Login with FB"
  2. Modal which displays FB's Web page is opened, there is button "Login With the Facebookapp"
  3. I tap on that, I am taken to FB native app, there is button "Continue"
  4. I tap on that, I am taken back to point 2. (ie. modal with Web page)

And that basically it, like infinite loop which I can only "exit" by exiting whole "flow", thus not being able to Login with FB

I think the underlying issue for us was that we are using WIX RNN and it doesn't play well with this SDK (or maybe this SDK doesn't play well with RNN, anyhow), simply adding these lines solved issue:

- (BOOL)application:(UIApplication *)app
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  if ([[FBSDKApplicationDelegate sharedInstance] application:app openURL:url options:options]) {
    return YES;
  }

  return NO;
}

(even though we are not using RCTLinkingManager)

creativemind1 commented 4 years ago

Check your AppDelegate.m file.

This code:

if ([[FBSDKApplicationDelegate sharedInstance] application:application
                                                              openURL:url
                                                    sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                                                            annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
        ]) {
     return YES;
   }

should be above this code:

  if ([RCTLinkingManager application:application openURL:url options:options]) {
    return YES;
  }

Otherwise, RCTLinkingManager will process the link instead of FBSDK

I have used your code and it is now navigation back to the App but with error "Login Failed". LoginManager.logInWithPermissions is failing. Any comments over here?

VNadygin commented 3 years ago

@creativemind1 I used to have the same issue and fixed it by updating didFinishLaunchingWithOptions. https://developers.facebook.com/docs/facebook-login/ios/ Note that you should modify 2 methods in app delegate