iOS 应用程序触发 google 云功能的最佳方式

Best way to trigger a google cloud function by an iOS app

我正在构建一个 Swift 应用程序,它基于 URL 作为主键从 MongoDB 中提取数据。如果 URL 尚未在集合中,那么我想触发一个 Google 云函数去检查 URL 并将其添加到数据库中。

在查看 Cloud Function 触发选项时,我没有看到一种简单的方法来监控对 MongoDB 的写入(计划是 table 新的 URLs 将通过云函数获得 运行。)

我看到了 PubSub 和 Firebase 触发器,PubSub 似乎是最好的选择,但是我找不到很多关于从 iOS 向 PubSub 发布消息的信息(尽管有很多关于订阅)

我确实看过很多 iOS FireBase 文档。我想知道是否最好写入 Firebase 并触发它,所以应用程序的每个用户在输入无法识别的 URL 时,应用程序都会将 URL 写入 Firebase,这会触发云功能。或者我应该弄清楚如何让 iOS 应用程序向 PubSub 主题发布消息?现在我不需要超快的响应,因为系统预计需要时间来处理新的 URLs。

您可能会有更好的体验写入 Firebase 并让 Firebase 触发您的 Cloud Functions。不幸的是 Swift 中没有官方支持的 Cloud Pub/Sub 客户端。

Best way to trigger a google cloud function by an iOS app

根据你的问题标题和 body,我认为最好的方法是从你的应用程序调用 Callable Cloud Function

如文档中所述:

The Cloud Functions for Firebase client SDKs let you call functions directly from a Firebase app. To call a function from your app in this way, write and deploy an HTTPS Callable function in Cloud Functions, and then add client logic to call the function from your app.

关于如何编写 Cloud Function 以及如何从您的 iOS 应用调用它的所有详细信息都可以在上面提到的文档中找到。