【问题标题】:Sending APNS mutable_content with FCM Java API使用 FCM Java API 发送 APNS mutable_content
【发布时间】:2018-03-07 08:12:04
【问题描述】:

根据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 Boot 服务器中,用于向用户发送通知。

【问题讨论】:

  • 我相信密钥被命名为mutable-content(用连字符代替下划线),并且应该设置为Aps。当前的 API 不支持此功能。你能提交一个功能请求吗?
  • @HiranyaJayathilakaas 根据 Firebase 文档 (firebase.google.com/docs/cloud-messaging/…),当直接通过 API 调用发送时,它在 Firebase 中应该是 mutable_content。这就是我使用mutable_content 的原因。我试过mutable-content 也没有用。我将为此提出功能请求
  • 您链接到的文档是指旧版 FCM API。 Java SDK 使用v1 API,应将其指定为mutable-content。但是现在 Java API 没有公开它,所以不管怎样都没有关系。如果您要直接使用 Node.js SDK 或 REST API,您可能可以设置此选项。

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


【解决方案1】:

我也在搜索不同的网站,最后,我得到了正确的输出(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();

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-25
    • 1970-01-01
    • 1970-01-01
    • 2021-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多