2

As per here and here, FCM supports sending mutable_content variable as a boolean when using FCM REST APIs. But I couldn't find an equivalent method in the 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);

Tried setting it as a custom data value in ApnsConfig, however, it does not work.

PS: This method runs in a Spring boot server to send the notification to users.

Community
  • 1
  • 1
Sudara
  • 4,769
  • 3
  • 34
  • 39
  • I believe the key is named `mutable-content` (with a hyphen instead of underscore), and should be set on `Aps`. The current API doesn't support this. Can you please file a feature request? – Hiranya Jayathilaka Mar 07 '18 at 17:51
  • @HiranyaJayathilakaas per the Firebase documentation (https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json) it should be `mutable_content` in Firebase when sending via an API call directly. That's why I used `mutable_content`. I tried with `mutable-content` didn't work either. I'll file a feature request for this – Sudara Mar 07 '18 at 18:28
  • 1
    The documentation you've linked to refers to the legacy FCM API. The Java SDK uses the [`v1` API](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages) where this should be specified as `mutable-content`. But right now the Java API doesn't expose it, so it wouldn't matter either way. You can probably set this option if you were to use the Node.js SDK or the REST API directly. – Hiranya Jayathilaka Mar 07 '18 at 22:32

1 Answers1

4

I am Also searching for different websites and finally, I got proper Output(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();

in this code, we passing custom data also.

Manideep
  • 353
  • 3
  • 13