【发布时间】:2018-04-12 08:37:48
【问题描述】:
所以我有这个代码:
export default class Login extends Component {
constructor(props){
super(props);
this._fbAuth = this._fbAuth.bind(this);
this.login = this.login.bind(this);
}
login(){
this.props.navigator.push({
id: "Home",
});
}
_fbAuth(){
LoginManager.logInWithReadPermissions(['public_profile']).then(
function(result) {
if (result.isCancelled) {
alert('Login cancelled');
} else {
alert('Login success with permissions: '+result.grantedPermissions.toString());
this.login();
}
},
function(error) {
alert('Login fail with error: ' + error);
}
);
}
render() {
return (
<View style={styles.container}>
<View style={styles.botbuttoncontainer}>
<Text style={styles.otherlogintext}>Or log in using</Text>
<View style={styles.otherloginbutton}>
<TouchableOpacity style={styles.facebookbutton} activeOpacity={0.5} onPress={()=>this._fbAuth()}>
<Icons name="logo-facebook" size={20} color="white"/>
</TouchableOpacity>
<TouchableOpacity style={styles.twitterbutton} activeOpacity={0.5}>
<Icons name="logo-twitter" size={20} color="white"/>
</TouchableOpacity>
<TouchableOpacity style={styles.googlebutton} activeOpacity={0.5}>
<Icons name="logo-googleplus" size={20} color="white"/>
</TouchableOpacity>
</View>
</View>
</View>
);
}
}
每次我尝试使用 facebook 登录时都会成功。但我总是收到警告说
"可能的未处理的 Promise Rejection(id:0): TypeError: undefined is 不是函数(评估 'this.login()')"
我尝试绑定函数_fbAuth 并在构造函数上登录,但它仍然给出相同的警告。
【问题讨论】:
标签: javascript reactjs react-native fbsdk react-native-fbsdk