diff --git a/src/main/java/com/notnoop/apns/PayloadBuilder.java b/src/main/java/com/notnoop/apns/PayloadBuilder.java index 798c22a0..0c326ca3 100644 --- a/src/main/java/com/notnoop/apns/PayloadBuilder.java +++ b/src/main/java/com/notnoop/apns/PayloadBuilder.java @@ -34,6 +34,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; + import com.fasterxml.jackson.databind.ObjectMapper; import com.notnoop.apns.internal.Utilities; @@ -262,6 +263,19 @@ public PayloadBuilder instantDeliveryOrSilentNotification() { return this; } + /** + * In order for the push notification to get picked up by UNNotificationServiceExtension, the + * aps dictionary must include 'mutable-content' key with value set to 1. + * + * @see https://developer.apple.com/reference/usernotifications/unnotificationserviceextension + * + * @return this + */ + public PayloadBuilder mutableContent() { + aps.put("mutable-content", 1); + return this; + } + /** * Set the notification localized key for the alert body * message. diff --git a/src/test/java/com/notnoop/apns/PayloadBuilderTest.java b/src/test/java/com/notnoop/apns/PayloadBuilderTest.java index 95ebe28b..6d2c0427 100644 --- a/src/test/java/com/notnoop/apns/PayloadBuilderTest.java +++ b/src/test/java/com/notnoop/apns/PayloadBuilderTest.java @@ -570,4 +570,14 @@ public void instantMessageWithAlert() { final String actual = builder.toString(); assertEqualsJson(expected, actual); } + + @Test + public void mutableConentMessage() { + final PayloadBuilder builder = new PayloadBuilder(); + builder.mutableContent(); + + final String expected = "{\"aps\":{\"mutable-content\":1}}"; + final String actual = builder.toString(); + assertEqualsJson(expected, actual); + } }