我正在使用 react-native-fbsdk 0.4.0 并遵循https://github.com/facebook/react-native-fbsdk中的步骤。添加本机 FBSDK 后,我尝试了本机 Object-C 测试应用程序,并且 FB 登录按钮可以正常工作。
但是,我遇到了与这篇文章React Native Facebook Login using official fbsdk相同的问题。
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
const FBSDK = require('react-native-fbsdk');
const {
LoginButton,
AccessToken
} = FBSDK;
var Login = React.createClass({
render: function() {
return (
<View>
<LoginButton
publishPermissions={["publish_actions"]}
onLoginFinished={
(error, result) => {
if (error) {
alert("login has error: " + result.error);
} else if (result.isCancelled) {
alert("login is cancelled.");
} else {
AccessToken.getCurrentAccessToken().then(
(data) => {
alert(data.accessToken.toString())
}
)
}
}
}
onLogoutFinished={() => alert("logout.")}/>
</View>
);
}
});
AppRegistry.registerComponent('fbsdk_rn', () => Login);
非常感谢任何帮助。谢谢。
更新:只是解决我的问题,希望能激励别人。我从https://github.com/magus/react-native-facebook-login检查了这个“react-native-facebook-login” 。
整个过程几乎相同,只是“AppDelegate.m”中有一个不同的“头文件导入”
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
我添加了 FBSDKLoginKit.h 的第二个导入,它可以工作。