【问题标题】:How do i get the response from a Firebase function to client in ionic如何在 ionic 中从 Firebase 函数向客户端获取响应
【发布时间】:2019-05-16 18:42:43
【问题描述】:

我试图了解承诺是如何从 firebase 函数响应客户端的方式工作的,我将在这里举一个非常简单的例子:

这是保存一些数据的离子方法,然后在firebase中触发一个函数:

helloworld() {
   this.db.list(`/helloWorld/${this.userId}`).push({status: false})
     .then(res => console.log(res))
}

Firebase 函数触发

exports.helloWorld = database
 .ref('helloworld/{id}')
 .onWrite((change, context) => {
   const data = change.after.val();
   const id = context.params.id;

return admin
  .database()
  .ref(`/helloWorld/${id}`)
  .set({ status: true }).then((res) => res);

});

【问题讨论】:

    标签: firebase ionic-framework firebase-realtime-database ionic3 google-cloud-functions


    【解决方案1】:

    所有后台类型的函数,包括实时数据库触发器,都不会向做出更改的客户端“返回”任何内容。客户唯一知道的是它做出了改变。

    后台函数返回的 Promise 仅用于一个目的 - 在该函数的所有异步工作完成时通知 Cloud Functions。他们不会向客户传达任何信息。

    如果您需要后台功能将某些信息传递回客户端,则需要某种沟通渠道。该函数可以在与客户端商定的位置写回数据库,也可以使用 Firebase Cloud Messaging 来 ping 应用程序。没有一种正确的方法可以做到这一点 - 您必须想出适合您需求的东西。

    【讨论】:

      猜你喜欢
      • 2019-05-29
      • 2023-03-03
      • 1970-01-01
      • 2021-03-12
      • 2020-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-16
      相关资源
      最近更新 更多