Skip to content

Commit 3c4666c

Browse files
author
Cem Catikkas
committed
Added method to set 'mutable-content' to 1. Fixes #321, #328.
1 parent 180a190 commit 3c4666c

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/main/java/com/notnoop/apns/PayloadBuilder.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.Collection;
3535
import java.util.HashMap;
3636
import java.util.Map;
37+
3738
import com.fasterxml.jackson.databind.ObjectMapper;
3839
import com.notnoop.apns.internal.Utilities;
3940

@@ -263,11 +264,24 @@ public PayloadBuilder instantDeliveryOrSilentNotification() {
263264
}
264265

265266
/**
266-
* Set the notification localized key for the alert body
267-
* message.
267+
* In order for the push notification to get picked up by UNNotificationServiceExtension, the
268+
* aps dictionary must include 'mutable-content' key with value set to 1.
268269
*
269-
* @param key the localizable message body key
270-
* @return this
270+
* @see https://developer.apple.com/reference/usernotifications/unnotificationserviceextension
271+
*
272+
* @return this
273+
*/
274+
public PayloadBuilder mutableContent() {
275+
aps.put("mutable-content", 1);
276+
return this;
277+
}
278+
279+
/**
280+
* Set the notification localized key for the alert body message.
281+
*
282+
* @param key
283+
* the localizable message body key
284+
* @return this
271285
*/
272286
public PayloadBuilder localizedKey(final String key) {
273287
customAlert.put("loc-key", key);

src/test/java/com/notnoop/apns/PayloadBuilderTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,4 +570,14 @@ public void instantMessageWithAlert() {
570570
final String actual = builder.toString();
571571
assertEqualsJson(expected, actual);
572572
}
573+
574+
@Test
575+
public void mutableConentMessage() {
576+
final PayloadBuilder builder = new PayloadBuilder();
577+
builder.mutableContent();
578+
579+
final String expected = "{\"aps\":{\"mutable-content\":1}}";
580+
final String actual = builder.toString();
581+
assertEqualsJson(expected, actual);
582+
}
573583
}

0 commit comments

Comments
 (0)