Firebase 推送通知与 childAdd 监听器 [英] Firebase push notification vs childAdd listener

查看:29
本文介绍了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 监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆