React-native-fbsdk: Can not display an alert when using LoginManager

Created on 16 May 2016  路  7Comments  路  Source: facebook/react-native-fbsdk

I am trying to do an alert when logging into facebook via the following code on iOS.

LoginManager.logInWithReadPermissions(['email', 'public_profile']).then(
      function(result) {
        alert("Finished loging into facebook");
      },
     function(error) {
      alert("Problem with login");
    },
);

The login dialog is shown and when I either cancel or log in, I am getting the following warning without the alert:

Warning: Attempt to present <UIAlertController: 0x7ff705593770> on <FBSDKContainerViewController: 0x7ff7019e5820> whose view is not in the window hierarchy!

Any idea how to fix this?

Most helpful comment

This was fixed for me by enabling Keychain sharing in the Capabilites section of the app settings.

image

Not sure how its related but it was on a stack overflow issue similar to this one.

Edit: this is on xcode 8 building for iOS 10.

All 7 comments

Exactly same issue here.

Warning: Attempt to present <UIAlertController: 0x7fe6f4d22320> on <FBSDKContainerViewController: 0x7fe6f4d1db00> whose view is not in the window hierarchy!

I think i a have a similar problem with LoginManager, errors alerts works but i can't get the login success alert, my app stay on a white page with URL : https://m.facebook.com/v2.7/dialog/oauth/confirm

No errors in Xcode console... Any idea ?

Here is my code :

const FBSDK = require('react-native-fbsdk');
const {
  LoginButton,
  LoginManager,
  AccessToken
} = FBSDK;

// Attempt a login using the Facebook login dialog asking for default permissions.
LoginManager.logInWithReadPermissions(['public_profile']).then(
  function(result) {
    alert(result);
    console.log(result);
    if (result.isCancelled) {
      alert('Login cancelled');
    } else {
      alert('Login success with permissions: '
        +result.grantedPermissions.toString());
    }
  },
  function(error) {
    alert('Login fail with error: ' + error);
  }
);

Sorry i found the problem...
I missed to configure my AppDelegate.m like explain in #72

I have the same issue when call login facebook after click an alert. I have configed openURL for FBSDK in AppDelegate.m It doesn't open Facebook URL.
" -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"
"Warning: Attempt to present on whose view is not in the window hierarchy!"

Here is my code.

 _showAlertFacebookLogin () {
    Alert.alert(
      'Login Facebook',
      'Please Login Facebook',
      [
        {text: 'No thanks!', onPress: () => {}, style: 'cancel'},
        {text: 'OK', onPress: () => this._loginFacebook()}
      ]
    )
  }

  _loginFacebook () {
    const permissions = ["public_profile", "user_posts", "user_photos", "user_location"];
    LoginManager.logInWithReadPermissions(permissions).then(
      (result) => {
        if (result.isCancelled) {
          alert('Login Facebook has been canceled');
        } else {
          AccessToken.getCurrentAccessToken().then(
            (data) => {
              this._saveFacebookAccessToken(data.accessToken.toString());
          });
          alert('You have logged in facebook successfully with granted permissions: ' +
            result.grantedPermissions.toString());
        }
      },
      (error) => {
        Alert.alert("Login Facebook", 'ERROR:' + error);
      }
    )
  }  
  • 1 for fix this :).
    Thanks

@congnguyen91 Were you able to resolve the issue? I am running into same problems. Please share your solution if you were able to solve the problem. Thanks in advance.

I use Timeout for delay 500ms. Wait for Alert completely disappearing.

_showAlertFacebookLogin () {
    Alert.alert(
      'Login Facebook',
      'Please Login Facebook',
      [
        {text: 'No thanks!', onPress: () => {}, style: 'cancel'},
        {text: 'OK', onPress: () => {
          TimerMixin.clearTimeout(this._loginTimeout);
          this._loginTimeout = setTimeout(() =>
            this._loginFacebook(),
            500
          );
        }}
      ]
    )
  }

This was fixed for me by enabling Keychain sharing in the Capabilites section of the app settings.

image

Not sure how its related but it was on a stack overflow issue similar to this one.

Edit: this is on xcode 8 building for iOS 10.

Was this page helpful?
0 / 5 - 0 ratings