【问题标题】:How to use firebase features in react native如何在 React Native 中使用 Firebase 功能
【发布时间】:2017-09-16 12:43:46
【问题描述】:

我想使用 react native 编写一个移动应用程序。我想使用 firebase,因为它可以节省我很多时间。我以前在我的网络应用程序中使用过 firebase,它运行得很好。现在 react native 实际上是一个真正的原生应用程序,我正在考虑是否可以为我的应用程序使用 firebase 功能。比如第三方认证、深度链接等。我知道,虽然都是用 Javascript 写的,但 react native 根本就不是 web 应用。我特别想使用几个功能。 Google 身份验证、云消息传递和一些分析功能。有什么方法可以将它们放入我的应用程序中,就像我用 Swift 或 Java 编写我的应用程序一样?

【问题讨论】:

  • 技术建议与 Stack Overflow 无关。但是这个搜索的前几个结果似乎都相关:google.com/webhp?#q=firebase+react+native
  • 为什么不使用 firebase js API?
  • 我认为API仅用于数据库和存储。

标签: firebase react-native


【解决方案1】:

首先你可能需要在 package.json 文件的依赖项下添加 firebase

"dependencies": {
    "firebase": "^3.9.0",
    "react": "^16.0.0-alpha.6",
    "react-native": "0.44.0",
  },

之后导入 firebase

import * as firebase from 'firebase';

然后进行通常的 firebase 初始化

const config = {
        apiKey: "xxxxxxxxxx-xxxxxxxxxxxxx",
        authDomain: "xxxxxxxxxxx.firebaseapp.com",
        databaseURL: "https://xxxxxxxxxx.firebaseio.com",
        projectId: "xxxxxxxxxx",
        storageBucket: "xxxxxxxxxx.appspot.com",
        messagingSenderId: "xxxxxxxxxx"
      };
const firebaseApp = firebase.initializeApp(config);

现在已将 firebase 连接到您的 react-native 应用程序,您可以像这样从数据库中检索内容

firebaseApp.database().ref("xxxxxx").on('value', (snap) => {
        console.log(snap.val());
});

剩下的也可以很容易地计算出来

如果您仍需要更多帮助,可以查看以下链接:https://firebase.googleblog.com/2016/01/the-beginners-guide-to-react-native-and_84.html

【讨论】:

    猜你喜欢
    • 2018-03-07
    • 2021-12-10
    • 2020-08-12
    • 2020-10-02
    • 2020-07-27
    • 1970-01-01
    • 2021-09-18
    • 2019-01-07
    • 1970-01-01
    相关资源
    最近更新 更多