12

我尝试按照入门教程为 iOS 设置一个新的 React Native 项目。但是登录按钮似乎不起作用。任何帮助表示赞赏。

这是 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);

以及模拟器的截图: 在此处输入代码

4

1 回答 1

6

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

如果您使用 react-native-sdk v0.2.0+,rnpm 将负责这一步,您可以按照此处的提示完成设置。

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

于 2016-06-06T22:19:50.293 回答