Firebase push notification vs childAdd listener(Firebase 推送通知与 childAdd 监听器)
问题描述
我正在开发基于 Firebase 的移动应用的好友请求模块,因此我正在考虑选择推送通知的方式.
I'm working in a friend request module for mobile app base on Firebase so I'm considering to choose the way that notification is pushed.
假设 userA 请求与 userB 成为朋友.现在有2个想法:
- userA 向一个简单的服务器发送请求,然后它会调用 FCM 向 userB 发送通知.
- 创建一个服务来侦听 Firebase 实时数据库中更改的数据,然后 userA 将在该数据库上进行更改,并且通知将显示在 userB 设备上.
Assume that userA request to be friend with userB. There're 2 ideas now:
- userA send request to a simple server then it will call FCM to send notification to userB.
- Make a service that listen to data changed in Firebase realtime database then userA will make change on that db and notification will be shown on userB device.
我认为两者都可以实现,但哪个更好,为什么?请给我一些建议...
I think both are possible to implement but what is better, and why? Please give me some advice about this..
提前致谢.
推荐答案
使用任何一个都可以.
但是,这里要考虑的一点是,当实时数据库保持侦听器处于活动状态时,它还会在用户设备上保持一个打开的套接字,这会增加电池消耗.
However, a point to consider here is when keeping a listener active for the Real-time database, it also keeps an open socket on the user's device which adds to battery consumption.
而对于 FCM,它只会在需要发送通知时触发.如果 好友请求 对应用来说不是很重要,我认为使用 FCM 是一种可行的方法.
While for FCM, it will only trigger once there is a notification is needed to be sent. If a friend request isn't really that app critical, I think using FCM is a way to go.
您是否也考虑过同时使用两者?如果用户当前在线,最好使用实时数据库,但如果用户离线(例如不使用应用程序).在这种情况下,您可以设置它以便向用户发送通知.
Have you also considered using both? If the user is currently online, it would be good to use the Real-time DB, but the childAdded
won't be triggered if the user is offline (not using the app for instance). In that case, you can set it so that a notification will be sent to the user.
在你的场景中重要的是好友请求应该先保存在你的数据库或应用服务器中,这样才会触发相应的动作(FCM通知或实时数据库更新).
The important thing in your scenario is that the friend request should be saved first in your database or app server, so that it will trigger the corresponding action (FCM notification or Real-time DB update).
这篇关于Firebase 推送通知与 childAdd 监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Firebase 推送通知与 childAdd 监听器
基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01