c# - 有什么方法可以使用 Android 应用程序捕获云 Firestore 上的任何更新,然后在 C# 应用程序中触发监听事件?
问题描述
我的团队想要将 android UI 与 Cloud Firestore 数据库一起使用。我们的一些团队是 c# 开发人员。我们希望创建一个事件,以便在云 Firestore 数据库发生更改时始终触发。有什么办法吗?
我想在数据库更改时触发此方法。
// [START fs_listen_document] sample event trigger c# using Google.Cloud.Firestore;
DocumentReference docRef = db.Collection("test").Document("subtest");
FirestoreChangeListener listener = docRef.Listen(snapshot =>
{
Console.WriteLine("Callback received document snapshot.");
Console.WriteLine("Document exists? {0}", snapshot.Exists);
if (snapshot.Exists)
{
Console.WriteLine("Document data for {0} document:", snapshot.Id);
Dictionary<string, object> city = snapshot.ToDictionary();
foreach (KeyValuePair<string, object> pair in city)
{
Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
}
}
});
// [END fs_listen_document]
解决方案
当 Firestore 发生任何事情时,客户端应用程序无法简单地触发一些代码。有数据库查询侦听器,但它们不会按您期望的方式工作。它们旨在随着时间的推移监视特定查询结果的结果。
提供的从 Firestore 接收事件的方法是通过Cloud Functions。您可以编写将在文档更改与您提供的模式匹配时触发的后端代码。然后,您可以决定如何处理。如果您认为客户端应用程序对更新感兴趣,也许您想向它发送推送通知。
推荐阅读
- android - 您的设备与此版本不兼容 - 显示在所有设备上
- php - 在 PHP 中对数组元素进行分组和重新排序
- html - 如何将包含 html 数据的数据框写入磁盘?
- react-native - react-native 如何在子组件中获取父组件背景颜色
- jmeter - 如何在jmeter中获得每秒500的吞吐量
- bash - grep 文件名存储在变量中的多个文件
- javascript - 如何在javascript中打印所有百分比超过70%的学生姓名?
- reactjs - 仅当输入值等于 for 循环中某个数组的当前值时才更新输入值
- python - 关于连接函数的 Python 问题得到不同的输出
- javascript - How to adapt function to make it target element that invoked it?