使用官方fbsdk响应本机Facebook登录 [英] React Native Facebook Login using official fbsdk

查看:101
本文介绍了使用官方fbsdk响应本机Facebook登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过设置新的React Native项目来遵循入门教程适用于iOS.但是loginbutton似乎不起作用.任何帮助表示赞赏.

I tried following the starter tutorial by setting up a new React Native Project for iOS. But the loginbutton doesn't seem to be working. Any help is appreciated.

这是index.ios.js:

Here's the 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);

以及模拟器的屏幕截图:

And the screenshot of the emulator:

推荐答案

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

You need to link the sdk's iOS project in your app's project.

如果您使用的是react-native-sdk v0.2.0 +,rnpm将负责此步骤,您可以按照提示操作

If you're using react-native-sdk v0.2.0+, rnpm will take care of this step and you can follow the tips here to complete set up.

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

If you're using the older version, you need to link react-native-fbsdkxxx.xcodeproj in YourApp.xcodeproj. Follow the manual linking steps in https://facebook.github.io/react-native/docs/linking-libraries-ios.html

这篇关于使用官方fbsdk响应本机Facebook登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆