我想使用 token 向一批设备发送消息,因为我有不同的接收器组,这些接收器组非常动态且可以更改。我在后端 Spring Boot 服务器上定义了组,并且 Message.Builder 只有一个“setToken”方法。这是否意味着我必须循环所有 token 才能发送消息?
最佳答案
sending messages to multiple devices 的文档建议您需要使用MulticastMessage为此。
// Create a list containing up to 100 registration tokens.
// These registration tokens come from the client FCM SDKs.
List<String> registrationTokens = Arrays.asList(
"YOUR_REGISTRATION_TOKEN_1",
// ...
"YOUR_REGISTRATION_TOKEN_n"
);
MulticastMessage message = MulticastMessage.builder()
.putData("score", "850")
.putData("time", "2:45")
.addAllTokens(registrationTokens)
.build();
BatchResponse response = FirebaseMessaging.getInstance().sendMulticast(message);
// See the BatchResponse reference documentation
// for the contents of response.
System.out.println(response.getSuccessCount() + " messages were sent successfully");
关于java - 是否可以使用 Firebase Admin SDK 将消息发送到 FCM 客户端的一批 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60131380/