【问题标题】:How to connect google-cloud-firestore to swift?如何将 google-cloud-firestore 连接到 swift?
【发布时间】:2021-07-28 15:17:48
【问题描述】:

我无法使用 Firestore-CLI 将 Firestore-cloud 连接到 xcode,但无法这样做。

所以,现在,我正在尝试将 Firestore 连接到无服务器 - https://firebase.google.com/docs/firestore/extend-with-functions ,在控制台中是 -
https://console.cloud.google.com

我有以下功能-

1)。给定示例中的函数是 - "helloWorld" ,代码是 -

      exports.helloWorld = (req, res) => {
      let message = req.query.message || req.body.message || 'Hello World!';
      res.status(200).send(message);
       };

-- 它被部署为 - https://myregion-testpro-92351.cloudfunctions.net/function-1

2)。我还测试了另一个函数“helloHttp”,代码是-

      exports.helloHttp = (req, res) => {
      res.send(`Hello ${escapeHtml(req.query.name || req.body.name || 'World')}!`);
       };

-- 它被部署为 - https://myregion-testpro-92351.cloudfunctions.net/function-5

以上函数部署成功。

另外,我的 swift Viewcontroller 代码是 -

    import UIKit
    import Firebase
    class TestViewController:
    UIViewController {
    @IBAction func Test(_ sender: Any) {  } }

以上两个函数的package.json是-

       {
      "name": "sample-http",
       "version": "0.0.1"
        }

我有以下问题-

我应该在按钮内放什么 - 上面“TestViewController”中的“@IBAction func Test(_ sender: Any) { } }”来实现这两个功能,1)。 “function-1”,即“helloWorld”和 2)。 “function-5”,即“helloHttp”在xcode控制台打印“HelloWorld”。

【问题讨论】:

  • 您在这里至少有两个完全不同的问题。您应该考虑缩小重点,以便可以单独回答。
  • 好的,那么我最关心的是第二点。
  • 那么您应该编辑您的问题以反映这一点。包括您到目前为止尝试过的内容。文档中有一段关于如何做到这一点:firebase.google.com/docs/functions/callable
  • @jnpdx - 编辑了问题。
  • 您是否尝试过文档中用于从 Swift 调用函数的代码?您在哪里遇到问题?

标签: node.js swift google-cloud-firestore google-cloud-functions


【解决方案1】:

不久前我做了类似的事情,为您的应用程序功能部署功能,从终端部署它们。

要在您的应用程序中执行函数和/或传入参数,您可以使用 AlamoFire。每个函数都有自己的 URL,AlamoFire 可以检索它,您可能希望从那里传递所需的任何数据。

【讨论】:

  • 在这种情况下,Alamofire 与内置 URLSession 相比有什么优势?
  • 请看我问题的第一行,我无法通过 CLI 完成
猜你喜欢
  • 1970-01-01
  • 2021-03-27
  • 2020-04-06
  • 2017-01-07
  • 1970-01-01
  • 2017-03-17
  • 2021-12-07
  • 1970-01-01
  • 2019-07-11
相关资源
最近更新 更多