使用官方fbsdk反应原生Facebook登录

时间:2016-05-14 18:32:17

标签: react-native fbsdk react-native-fbsdk

我尝试通过为iOS设置新的React Native Project来关注启动器tutorial。但登录按钮似乎不起作用。任何帮助表示赞赏。

这里是index.ios.js:

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';

const FBSDK = require('react-native-fbsdk');
const {
  LoginButton
} = 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 {
                alert("login has finished with permissions: " + result.grantedPermissions)
              }
            }
          }
          onLogoutFinished={() => alert("logout.")}/>
      </View>
    );
  }
});

class AwesomeProject extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text>
          Login to Facebook
        </Text>
        <Login />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  shareText: {
    fontSize: 20,
    margin: 10,
  }
});

AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);

模拟器的屏幕截图: enter code here

1 个答案:

答案 0 :(得分:6)

您需要在应用的项目中链接sdk的iOS项目。

如果您正在使用react-native-sdk v0.2.0 +,则rnpm将负责此步骤,您可以按照提示here完成设置。

如果您使用的是旧版本,则需要在YourApp.xcodeproj中链接react-native-fbsdkxxx.xcodeproj。按照https://facebook.github.io/react-native/docs/linking-libraries-ios.html

中的手动链接步骤操作