使用 Facebook 登录时不会触发 onLoginFinished 回调

Pav*_*ndu 5 react-native react-native-fbsdk

我建立一个简单的阵营原生应用程序,它实现“登录与Facebook的”使用反应本地-fbsdk 我可以登录和注销从按钮改变登录注销时记录有凭据,但onLoginFinished回调永远不会被解雇,虽然onLogoutFinished工作正常。

这是我的代码:

import React, { Component } from 'react';
import { View,Alert,Button,Text } from 'react-native';
import { LoginButton, AccessToken } from 'react-native-fbsdk';

export default class Login extends Component {
  constructor(props) {
    super(props);
    this.state = {
      userInfo: null
    }
  }

  onFacebookLoginFinished = (error, result) => {
    if (error) {
      Alert.alert("login has error: " + result.error);
    } else if (result.isCancelled) {
      Alert.alert("login is cancelled.");
    } else {
      AccessToken.getCurrentAccessToken().then(
        (data) => {
          Alert.alert(data.accessToken.toString())
          this.props.navigation.navigate('Home')
        }
      )
    }
  }

  render() {
    return (
      <View>
        <LoginButton
          onLoginFinished={this.onFacebookLoginFinished}
          onLogoutFinished={() => Alert.alert("logout.")}/>
      </View>
    );
  }
};
Run Code Online (Sandbox Code Playgroud)

Buw*_*era 2

我认为你应该尝试这个。

onLoginFinished={(error, result) => this.onFacebookLoginFinished(error, result)}
Run Code Online (Sandbox Code Playgroud)

将函数改为这样。

onFacebookLoginFinished (error, result){
    ...
}
Run Code Online (Sandbox Code Playgroud)