From f4423ff7160bb76c0fb2c9564589a34c47b35217 Mon Sep 17 00:00:00 2001 From: Cem Catikkas Date: Tue, 27 Dec 2016 22:37:08 +0300 Subject: [PATCH 1/2] Added method to set 'mutable-content' to 1. Fixes #321, #328. --- .../java/com/notnoop/apns/PayloadBuilder.java | 22 +++++++++++++++---- .../com/notnoop/apns/PayloadBuilderTest.java | 10 +++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/notnoop/apns/PayloadBuilder.java b/src/main/java/com/notnoop/apns/PayloadBuilder.java index 798c22a0..77f28070 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; @@ -263,11 +264,24 @@ public PayloadBuilder instantDeliveryOrSilentNotification() { } /** - * Set the notification localized key for the alert body - * message. + * 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. * - * @param key the localizable message body key - * @return this + * @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. + * + * @param key + * the localizable message body key + * @return this */ public PayloadBuilder localizedKey(final String key) { customAlert.put("loc-key", key); 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); + } } From 27f7817960683a861245b4521f680b9dce75be0f Mon Sep 17 00:00:00 2001 From: Cem Catikkas Date: Mon, 10 Apr 2017 21:20:39 -0600 Subject: [PATCH 2/2] Reverted javadoc for localizedKey so the only diff is mutable-content related. --- src/main/java/com/notnoop/apns/PayloadBuilder.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/notnoop/apns/PayloadBuilder.java b/src/main/java/com/notnoop/apns/PayloadBuilder.java index 77f28070..0c326ca3 100644 --- a/src/main/java/com/notnoop/apns/PayloadBuilder.java +++ b/src/main/java/com/notnoop/apns/PayloadBuilder.java @@ -277,11 +277,11 @@ public PayloadBuilder mutableContent() { } /** - * Set the notification localized key for the alert body message. + * Set the notification localized key for the alert body + * message. * - * @param key - * the localizable message body key - * @return this + * @param key the localizable message body key + * @return this */ public PayloadBuilder localizedKey(final String key) { customAlert.put("loc-key", key);