使用FCM Java API发送APNS mutable_content

时间:2018-03-07 08:12:05

标签: ios firebase apple-push-notifications firebase-cloud-messaging firebase-admin

根据herehere,FCM支持在使用FCM REST API时将mutable_content变量作为布尔值发送。但我无法在Firebase Admin Java API中找到等效方法。

final ApsAlert alert = ApsAlert.builder()
       .setTitle("Test notification")
       .setBody("Hello World")
       .build();

final Aps aps = Aps.builder()
       .setAlert(alert)
       .setBadge(messageCount)
       .setContentAvailable(messageCount > 10000)
       .setCategory("tesy")
       .build();

final ApnsConfig config = ApnsConfig.builder()
       .putHeader("apns-id", getMessageId())
       .setAps(aps)
       .putCustomData("type", "test")
       .putCustomData("mutable_content", true)
       .build();

remoteMessage.setApnsConfig(config);

尝试将其设置为ApnsConfig中的自定义数据值,但是,它不起作用。

PS:此方法在Spring引导服务器中运行,以将通知发送给用户。

1 个答案:

答案 0 :(得分:2)

我也在搜索其他网站,最后,我得到了正确的输出(IOS)

 final ApsAlert alert =
                    ApsAlert.builder()
                        .setTitle(notification.getEventType())
                        .setBody(notification.getEventDescription())
                        .build();
                final Aps aps =
                    Aps.builder()
                        .setAlert(alert)
                        .setContentAvailable(true)
                        .setMutableContent(false)
                        .build();
                final ApnsConfig apnsConfig =
                    ApnsConfig.builder()
                        .setAps(aps)
                        .putCustomData("eventId", notification.getEventNumber())
                        .putCustomData("category", notification.getCategory())
                        .putCustomData("priority", notification.getEventPriority())
                        .build();
                message =
                    Message.builder()
                        .setToken(notificationRequestDto.getTo())
                        .setApnsConfig(apnsConfig)
                        .build();

在此代码中,我们还传递自定义数据。