Send push notification to people nearby through Firebase Cloud Function without manually managing push tokens?

纵饮孤独 提交于 2021-02-11 15:59:04

问题


Seems like majority of solutions here require the developer to manually save each user's push token in addition to Firebase saving these tokens as well, then iterate through these and send out notifications. This is not really desirable since I would be storing push tokens in two separate places and need to make sure their lifecycle management is synchronized, which is error prone 😢Is there a better way?

Some options I considered:

  1. Give each user a person/unique topic, then map out a geolocation per topic; then filter through these locations, aggregate these topics into batches of 500 and send a push. This is probably the best option so far 🤷‍♂️ but seems like a silly use of topics API.
  2. Bucket users in cities, with each city corresponding to a topic; then find all cities near a location, and send a push to those topics. This is doable, but lots of complex city mapping code without much flexibility (vs. considering a simple radius).
  3. Manually store push token → user → geolocation; filter out the ones you want, then send a push to the token specifically. This is problematic for many reasons (multiple device management, push token lifecycle management, data duplication, etc.)

Ideally, there is a way to send out a push notification to a list of user IDs, without even touching push tokens, is there a way to do this?


回答1:


The only way to associate a device token to a user ID is to store that mapping yourself. You should also assume that one user could have multiple devices. FCM doesn't have a concept of a "user". It only knows device tokens. Your app has to bring the concept of a user, then map that to tokens in code.

Note that any messaging solution that requires topics is not "secure". Anyone can effectively receive messages from any topic.



来源:https://stackoverflow.com/questions/62140208/send-push-notification-to-people-nearby-through-firebase-cloud-function-without

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!