Does react-native-fbsdk-next open the facebook app natively or not?

627 Views Asked by At

I implemented the library in my project, but when calling facebook, a webview is always opened and not the native facebook app, even though I have it installed. This happens on IOS and Android. The idea would be to open the native app so that the user doesn't have to enter their login and password via the browser, because this flow is a very bad experience. Could someone give me a light? I already took a look at all possible topics on google, but nothing worked. Even putting it like:

LoginManager.setLoginBehavior("native_only")

Which is the prop that the LoginBehavior can receive.

Any response is welcome. Thank you for your attention.

const LoginWithFacebook = async () => {

  setLoadingFacebook(true)

  LoginManager.logOut();

  LoginManager.setLoginBehavior("native_only")

  const data = await LoginManager.logInWithPermissions(["public_profile", "email"]);

  if(data.isCancelled){
     return  setLoadingFacebook(false)
  }

  const responseToken = await AccessToken.getCurrentAccessToken();

  afterLoginComplete(responseToken?.accessToken?.toString());

}
1

There are 1 best solutions below

2
On

Have you added the following code to your AppDelegate.m?

- (BOOL)application:(UIApplication *)app
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
  NSString* fbappid = [infoDict objectForKey:@"FacebookAppID"];
  NSString *fbAppId = [RNCConfig envFor:@"FB_APP_ID"];

  [FBAEMReporter configureWithNetworker:nil appID:fbAppId reporter:nil]; // Replace {app-id} with your Facebook App id
  [FBAEMReporter enable];
  [FBAEMReporter handleURL:url];

  if ([[FBSDKApplicationDelegate sharedInstance] application:app openURL:url options:options]) {
    return YES;
  }

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

  return NO;
}