我想订阅FCM中的一个主题,以便同时向多个用户发送通知,并且我已经在列表中拥有所有用户,并且列表中包含令牌。所以我的问题是,用户列表如何订阅主题。谢谢
来源https://firebase.google.com/docs/cloud-messaging/manage-topics
我假设您使用java作为服务器端代码来管理主题和发送云消息。
在java中,您可以执行以下操作,一次为给定主题订阅多个FCM令牌。
// These registration tokens come from the client FCM SDKs.
List<String> registrationTokens = Arrays.asList(
"YOUR_REGISTRATION_TOKEN_1",
// ...
"YOUR_REGISTRATION_TOKEN_n"
);
// Subscribe the devices corresponding to the registration tokens to the
// topic.
TopicManagementResponse response = FirebaseMessaging.getInstance().subscribeToTopic(
registrationTokens, topic);
// See the TopicManagementResponse reference documentation
// for the contents of response.
System.out.println(response.getSuccessCount() + " tokens were subscribed successfully");