How to send firebase notification for all user at a time? [closed]

谁说胖子不能爱 提交于 2019-12-08 09:42:00

问题


I have an application which sends notification for multiple users at a time(not all user). So how to do this using Firebase Push Notification?


回答1:


You can use Topic Messaging

Based on the publish/subscribe model, FCM topic messaging allows you to send a message to multiple devices that have opted in to a particular topic.

Topic messaging supports unlimited topics and subscriptions for each app.

To subscribe to a topic, the client app calls Firebase Cloud Messaging subscribeToTopic() with the FCM topic name:

FirebaseMessaging.getInstance().subscribeToTopic("news");

To send a notification on topic :

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

{
  "to": "/topics/news",
  "data": {
    "message": "This is a Firebase Cloud Messaging Topic Message!",
   }
}

Read more at here : https://firebase.google.com/docs/cloud-messaging/android/topic-messaging




回答2:


To send notification to multiple users, you need to register the users a single topic example topic called Weather, then all users registered will get a notification.

To be able to send the push notification, you can use cloud functions:

Cloud Functions for Firebase lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your code is stored in Google's cloud and runs in a managed environment. There's no need to manage and scale your own servers.

more info here: https://firebase.google.com/docs/functions/



来源:https://stackoverflow.com/questions/49188386/how-to-send-firebase-notification-for-all-user-at-a-time

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