【问题标题】:Can multiple users subscribe to a topic at the same time whenever they are in a list in FCM多个用户是否可以在 FCM 中的列表中同时订阅一个主题
【发布时间】:2020-08-15 04:52:38
【问题描述】:

我想订阅 FCM 中的主题以同时向多个用户发送通知,并且我在列表中拥有所有用户,并且列表中包含令牌。所以我的问题是用户列表如何订阅主题。谢谢

【问题讨论】:

  • 可以看docs
  • TopicManagementResponse response = FirebaseMessaging.getInstance().subscribeToTopic(registrationTokens, topic);先生,当我在其中添加registrationTokens列表时,它要求我只添加字符串
  • required: String found: List,String 它显示之前的错误
  • 客户端应用程序可以订阅任何现有主题,也可以创建新主题。您不能使用客户端应用添加列表。
  • 先生,我想向多个用户发送通知,所以我选择主题消息,所以现在请建议任何其他方法来执行此操作,因为我正在发送包含 4,5 个用户的提案,所以我想发送通知所有用户

标签: android firebase push-notification firebase-cloud-messaging android-push-notification


【解决方案1】:

来自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");

【讨论】:

    猜你喜欢
    • 2018-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-11
    • 1970-01-01
    • 1970-01-01
    • 2018-06-17
    相关资源
    最近更新 更多