简体   繁体   English

Firebase与React-Native IOS应用程序的集成失败

[英]Firebase integration with React-Native IOS app is failing

I am trying to integrate the Firebase service with React-Native framework. 我正在尝试将Firebase服务与React-Native框架集成在一起。 I am trying to follow this tutorial in Udemy: https://www.udemy.com/the-complete-react-native-and-redux-course/ 我正在尝试在Udemy中遵循此教程: https ://www.udemy.com/the-complete-react-native-and-redux-course/

Steps I followed: 我遵循的步骤:

  1. Downloaded firebase using npm command: npm install --save react-native-firebase 使用npm命令下载的Firebase:npm install --save react-native-firebase
  2. Created a project in the firebase console. 在Firebase控制台中创建了一个项目。
  3. Pasted the config created by Firebase in the React-native code. 将Firebase创建的配置粘贴到React-native代码中。

    class App extends Component { App类扩展了组件{

     componentWillMount() { firebase.initializeApp({ apiKey: 'AIzaSyAMuW4adFuW_XoYvpvke_iHTvlAkuVJ7Fk', authDomain: 'authproj2.firebaseapp.com', databaseURL: 'https://authproj2.firebaseio.com', projectId: 'authproj2', storageBucket: 'authproj2.appspot.com', messagingSenderId: '654736603029' }); firebase.auth().onAuthStateChanged((user) => { if(user) { this.setState( {loggedIn:true} ); } else { this.setState( {loggedIn: false } ); } }); 

    } } }}

And in a different React component I am creating aa Login Form which has a Submit button. 在另一个React组件中,我正在创建一个带有Submit按钮的Login Form。

The onButtonPress function is : onButtonPress函数为:

    onButtonPress () {
    const { email , password } = this.state;

    this.setState({error: '', loading: true});

    firebase.auth().signInWithEmailAndPassword(email, password)
    .then(this.onLoginSuccess.bind(this))
    .catch(() => {
        firebase.auth().createUserWithEmailAndPassword(email, password)
        .then(this.onLoginSuccess.bind(this))
        .catch(this.onLoginFailure.bind(this));
    });
    }

These are the onLoginSuccess and OnLoginFailure functions: 这些是onLoginSuccess和OnLoginFailure函数:

onLoginSuccess () {
this.setState( {email:'', password:'', error:'', loading:false});

} }

onLoginFailure () {
this.setState( {error: "Authentication Failure!!", loading:false } );

} }

But when I click on the button no action takes place. 但是,当我单击按钮时,没有任何动作。 Ideally it should create an a new account if the email and password are entered for the first time and show a different page if the email and password are correct. 理想情况下,如果首次输入电子邮件和密码,它应该创建一个新帐户,如果电子邮件和密码正确,则显示一个不同的页面。 But somewhere the integration of Firebase with React-native is going wrong. 但是Firebase与React-native的集成出现了问题。

You are using web SDK which requires firebase package but you have got react-native-firebase package installed. 您正在使用需要firebase软件包的Web SDK,但已安装了react-native-firebase软件包。

If you want to go ahead with the code and firebase you have written then you should install firebase package. 如果要继续编写代码和firebase,则应安装firebase软件包。

To solve your problem you should install firebase package 要解决您的问题,您应该安装firebase软件包

However to properly leverage firebase in mobile environment, it is recommended to use react-native-firebase but in that case, the firebase.initializeApp({ becomes meaningless as the firebase initialization in mobile happens using Google-services.json and Google-services.plist files provided by firebase console in android and iOS respectively when using the react-native-firebase package. 但是,要在移动环境中正确利用Firebase,建议使用react-native-firebase但在这种情况下, firebase.initializeApp({变得毫无意义,因为移动设备中的Firebase初始化是使用Google-services.jsonGoogle-services.plist当使用react-native-firebase软件包时,分别由android和iOS中的firebase控制台提供的Google-services.plist文件。

If you want to go with react-native-firebase please refer this . 如果你想要去的反应,本机火力请参阅

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM