首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未定义react-native-fbsdk LoginManger

未定义react-native-fbsdk LoginManger
EN

Stack Overflow用户
提问于 2019-01-15 11:16:59
回答 1查看 317关注 0票数 2

我有一个关于react-native-fbsdk LoginManager的问题。我一直收到错误,“无法读取未定义的属性'loginWithReadPermissions‘。

我尝试了在其他帖子中找到的多种解决方案,但似乎都不能解决我的问题。

我成功地安装了ed react-native-fbsdk,并正确地将FBSDK框架导入到Xcode项目中。我还正确地链接了libRCTFBSDK.a文件。这样做之后,我的构建结果是成功的,但我一直收到错误消息"LoginManager未定义“。

有没有人能帮我一下?

下面是我使用LoginManager和LoginButton编写的代码:

代码语言:javascript
复制
import React from 'react';
import { Container, Content, Text, Button, View } from 'native-base';
import Loading from './Loading';
import { AccessToken, LoginManager, LoginButton } from 'react-native-fbsdk';

    class Login extends React.Component {
      constructor(props) {
        super(props);
      }

      onLoginFacebook = () => {
        LoginManager
          .logInWithReadPermissions(["public_profile", "email"])
          .then((result) => {
            if(result.isCancelled) {
              return Promise.reject(new Error("The user cancelled the request"));
            }

            console.log(`Login success with permissions: ${result.grantedPermissions.toString()}`);
            //get the access token
            return AccessToken.getCurrentAccessToken();
          })

          .then((data) => {
            const credential = firebase.auth.FacebookAuthProvider.credential(data.accessToken);
            return firebase.auth().signInWithCredential(credential);
          })

          .then((currentUser) => {
            console.log(`Facebook Login with user : ${JSON.stringify(currentUser.toJSON())}`);
          })

          .catch((error) => {
            console.log(`Facebook Login fail with error: ${error}`);
          });
      }

      render() {
        const {
          loading,
          error,
          success,
          locale,
        } = this.props;
        const { email } = this.state;

        if (loading) return <Loading />;

        return (

          <Container style={{backgroundColor: 'white'}}>
            <Content>
                <View padder>
                  <Button
                    containerStyle={{
                      padding: 10, 
                      width: 150, 
                      margin: 20, 
                      borderRadius: 4, 
                      backgroundColor: 'rgb(73, 104, 173)',
                    }}
                    style={{marginTop: 20}}
                    onPress={this.onLoginFacebook}
                  >
                    <Text style={{fontSize: 18, color: 'white'}}>
                      Login Facebook
                    </Text>
                  </Button>
                </View>
            </Content>
          </Container>
        );
      }
    }

    export default Login;

以下是xCode配置的截图:

EN

回答 1

Stack Overflow用户

发布于 2019-01-17 15:57:26

我遇到了同样的错误,经过长时间的搜索,我发现我必须降级到SDK版本4.38.0 (当时我使用的是v4.39.0 )。

安装之前的版本后,一切都像预期的那样工作。希望能有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54192247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档