【问题标题】:How to send Notification/message to iOS device using FCM through Java(Spring Boot)?如何通过 Java(Spring Boot)使用 FCM 向 iOS 设备发送通知/消息?
【发布时间】:2019-12-01 09:58:20
【问题描述】:

我已经实现了使用 com.google.android.gcm.server.Sender(在前端使用 FCM 生成的设备令牌)向 Android 发送通知的功能。 但是我也需要将通知发送到 iOS 设备,那么如何配置或更改以下为 Android 完成的代码以向 iOS 发送通知?

                Map<String, String> map = new HashMap<String, String>();
                map.put("message", message.toString());
                map.put("badge", Integer.toString(badgeCount));
                map.put("messageId", Integer.toString(emergencyMessage.getMessageId()));
                map.put("issuedDateStr",
                        (emergencyMessage.getIssuedDateStr() != null) ? emergencyMessage.getIssuedDateStr() : "");
                map.put("title", pjmProperties.getProperty(APP_TITLE));
                map.put("soundname", "default");
                map.put("notId", Integer.toString(RandomUtils.nextInt(50001, 75000)));

                Message messageObj = new Message.Builder().delayWhileIdle(false).setData(map).build();
                sender.send(messageObj, deviceData.getToken(), 1);

我应该如何编写代码以使用 FCM/GCM 向 iOS 设备发送通知?(而不是通过 APNS 发送)

【问题讨论】:

    标签: ios spring-boot push-notification firebase-cloud-messaging google-cloud-messaging


    【解决方案1】:

    为可能是 Android 或 IOS 的多个设备 ID 发送通知。

    您可以在 fireBase 中使用 MulticastMessage。

                        MulticastMessage multiCast = MulticastMessage.builder()
                            .putAllData(new HashMap<String, String>())
                            .setApnsConfig(ApnsConfig.builder().build())
                            .setAndroidConfig(AndroidConfig.builder().build())
                            .addAllTokens(Arrays.asList("token1","token2"))
                            .build();
    

    供参考:https://firebase.google.com/docs/cloud-messaging/send-message

    【讨论】:

      猜你喜欢
      • 2021-06-17
      • 1970-01-01
      • 2021-11-14
      • 2020-03-29
      • 1970-01-01
      • 2021-07-23
      • 2020-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多