React-native-fbsdk: LoginManager.logInWithReadPermissions using Facebook App fails to resolve/reject promise on iOS

Created on 8 Nov 2018  路  18Comments  路  Source: facebook/react-native-fbsdk

Environment

Environment:
OS: macOS High Sierra 10.13.6
Node: 10.11.0
Yarn: 1.10.1
npm: Not Found
Watchman: 4.9.0
Xcode: Xcode 10.0 Build version 10A255
Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed)
react: 16.2.0 => 16.2.0
react-native: 0.53.0 => 0.53.0

Description

On iOS, invoking LoginManager.logInWithReadPermissions provides an intermediary screen. Log in with the Facebook App > successfully authenticates, but returns back to the intermediary screen, rather than the source application. Using Log in with phone or email returns back to the source application.

Only upon hitting Cancel does the promise resolve or reject (in this case, it resolves with isCancelled as true).

The promise should resolve once authenticated using the Facebook App, and not bring us back to the choice screen.

Reproducible Demo

LoginManager.logInWithReadPermissions(['public_profile', 'email', 'user_friends', 'user_location'])
.then(console.log).catch(console.warn);

Most helpful comment

I have the same problem.
The issue only occurs on IOS.
It works perfectly fine on Android.
Yet still cannot find any solution.

All 18 comments

I have the same problem.
The issue only occurs on IOS.
It works perfectly fine on Android.
Yet still cannot find any solution.

same goes to me, any alternative like disabling the login via facebook application instead? I'll prefer temporary disable the login via application if this issue couldn't be solved quickly

I'm running into the same issue as above and haven't been able to find a solution. This is occurring on iOS for me as well, i'm running these versions: "react-native": "0.57.1" and "react-native-fbsdk": "^0.8.0"

Was trying to debug in the xCode and notice the SDK never callback when the login is successful.

Same issue isCancelled as true if you choose Log in with the Facebook App >, but it works if you manually enter email and password.

Found a solution, it works for me.
https://github.com/facebook/react-native/issues/12877#issuecomment-340312431

@Martian2Lee thank for saving my life. Good work bro.

Found a solution, it works for me.
facebook/react-native#12877 (comment)

I already have the following. Is Linking required to make this work?

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  return
  [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
}

I was able to do this by doing the following:

*Note this is on iOS only, I haven't tested this on android.

After following the installation and setup instructions here

  1. Download the react-native-fbsdk repo.
  2. Copy the RCTFBSDK.xcodeproj in the ios folder to the libraries folder in your apps expo project.
  3. Make sure you have the FB SDK source files in the~/Documents/FacebookSDK directory. Open xcode and open the RCTFBSDK.xcodeproj. Go to Build Settings and in the Framework Search Paths field add this path $(HOME)/Documents/FacebookSDK by clicking the "+" button.
  4. Open your apps .xcodeproj file in xcode and go to Build Settings and in the Framework Search Paths field add this path $(HOME)/Documents/FacebookSDK by clicking the "+" button.
  5. Be sure that the Build Phases > Link Binary with Libraries looks something like this. (Assuming you are using the same frameworks from the documentation prior to step one.

fbsdkinstall

  1. Open your apps .xcodeproj file in xcode again and build the project.

Worked for me so hope that helps.

@jmelendev don't work for me

@demoran23 have you find any solutions yet?
@Martian2Lee @jmelendev solutions unfotunately did not work for me

@jmelendev don't work for me

for step 6 try opening the .xcworkspace file instead

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}

func application(_ application: UIApplication, open url: URL,      sourceApplication: String?, annotation: Any) -> Bool {
    return   FBSDKApplicationDelegate.sharedInstance().application(application, open: url as URL!, sourceApplication: sourceApplication, annotation: annotation)
}

func applicationDidBecomeActive(application: UIApplication) {
    FBSDKAppEvents.activateApp()
}

Although above code is wrriten in swift.
you guys can confirm that all necessary code exist in AppDelegate.m file

@heyman333

I only have this on my

AppDelegate.m

`

  • (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {

return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation]

|| [RNGoogleSignin application:application openURL:url sourceApplication:sourceApplication annotation:annotation]

|| [RCTLinkingManager application:application openURL:url sourceApplication:sourceApplication annotation:annotation]

|| [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];

}
`

None of these responses work for me. I'm using cocoapods. My pod install looks fine. I have these installed

  pod 'FBSDKCoreKit'
  pod 'FBSDKLoginKit'
  pod 'FBSDKShareKit'

My function looks like this:

  handleFacebookLoginTap = () => {
    console.log('FB Tap');
    LoginManager.logInWithReadPermissions(['public_profile', 'email']).then(
      result => {
        if (!result.isCancelled) {
          AccessToken.getCurrentAccessToken().then(async data => {
            const authenticated = await this.props.authStore.authenticateWithFacebook(
              data.accessToken
            );
            if (authenticated === false) {
              this.handleRolePress('TRAINER');
            }
          });
        }
      },
      error => {
        console.log('Login fail with error: ' + error);
      }
    );
  };

When I press the FB button, all I get is the first log statement, then the error message. I get no errors or any indication what causes the error. I don't think the app is grabbing the profile and email parameters.

Updating the iOS Facebook SDK from 4.32 to 4.38 appears to have fixed this issue for me. 4.39 exhibited other problems.

I'll leave this issue open for now. If others chime in that this fix works for them, we can close it.

pod config:

pod 'FBSDKLoginKit', '4.38.0'
pod 'FBSDKShareKit', '4.38.0'
pod 'FBSDKCoreKit', '4.38.0'

4.38.0 resolved the issue for me.

With no further negative input, I'll go ahead and close this issue. It appears to be a bug that existed in 4.32 that does not exist in 4.38.

Was this page helpful?
0 / 5 - 0 ratings