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

查看:233
本文介绍了Firebase推送通知与childAdd监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为基于Firebase的移动应用的朋友请求模块工作,所以我正在考虑选择推送通知的方式。假设用户A请求与用户B的朋友。现在有两个想法:
- userA发送请求到一个简单的服务器,然后它会调用FCM发送通知给用户B.

- 使一个服务,监听数据在Firebase实时数据库中更改,然后userA将更改该数据库,通知将显示在用户B设备上。为什么?
请给我一些关于此的建议。



在此先感谢。

解决方案



然而,这里需要考虑的一点是如何保持实时数据库的监听器处于活动状态,也会在用户的设备上保持一个开放的插口,这会增加电池消耗。

对于FCM,只有在需要发送通知时才会触发。如果好友请求不是真正的应用程序关键,那么我认为使用FCM是一种方法。



您是否也考虑过使用?如果用户当前在线,最好使用实时数据库,但如果用户离线,则不会触发 childAdded not使用应用程序的例子)。在这种情况下,您可以进行设置,以便将通知发送给用户。



您的情况中最重要的是好友请求应先保存在数据库或应用程序服务器中,以便它会触发相应的操作(FCM通知或实时数据库更新)。

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.

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..

Thanks in advance.

解决方案

Using either one should be fine.

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.

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.

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天全站免登陆