Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 256962e

Browse files
author
Daniel Heid
committed
Add more aps dictionary items
1 parent 404b010 commit 256962e

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ This project is licensed under the LGPL License - see the [license](LICENSE) fil
4848
### 2.4.2
4949

5050
* Logging improvements (replace string concatenation)
51+
* Add more aps dictionary items: thread-id, category and target-content-id
5152

5253
### 2.4.1
5354

src/main/java/javapns/notification/PushNotificationPayload.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,36 @@ public void addSound(String sound) {
218218
put("sound", sound, this.apsDictionary, true);
219219
}
220220

221+
/**
222+
* Add an app-specific identifier for grouping related notifications.
223+
*
224+
* @param threadId the app-specific identifier for grouping related notifications
225+
*/
226+
public void addThreadId(String threadId) {
227+
logger.debug("Adding thread id [{}]", threadId);
228+
put("thread-id", threadId, this.apsDictionary, true);
229+
}
230+
231+
/**
232+
* Add a notification type
233+
*
234+
* @param category the notification type
235+
*/
236+
public void addCategory(String category) {
237+
logger.debug("Adding category [{}]", category);
238+
put("category", category, this.apsDictionary, true);
239+
}
240+
241+
/**
242+
* Add a identifier of the window brought forward
243+
*
244+
* @param targetContentId the notification type
245+
*/
246+
public void addTargetContentId(String targetContentId) {
247+
logger.debug("Adding target content id [{}]", targetContentId);
248+
put("target-content-id", targetContentId, this.apsDictionary, true);
249+
}
250+
221251
/**
222252
* Add a media attachment.
223253
*

src/test/java/javapns/notification/PushNotificationPayloadTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,38 @@ public void allowsToAddMediaAttachment() {
2929
assertThat(payload.getString("my-attachment"), is("https://some.url.local/attachement"));
3030

3131
}
32+
33+
@Test
34+
public void allowsToAddThreadId() {
35+
36+
pushNotificationPayload.addThreadId("myThreadId");
37+
38+
JSONObject payload = pushNotificationPayload.getPayload();
39+
JSONObject aps = payload.getJSONObject("aps");
40+
assertThat(aps.getString("thread-id"), is("myThreadId"));
41+
42+
}
43+
44+
@Test
45+
public void allowsToAddCategory() {
46+
47+
pushNotificationPayload.addCategory("myCategory");
48+
49+
JSONObject payload = pushNotificationPayload.getPayload();
50+
JSONObject aps = payload.getJSONObject("aps");
51+
assertThat(aps.getString("category"), is("myCategory"));
52+
53+
}
54+
55+
@Test
56+
public void allowsToTargetContentId() {
57+
58+
pushNotificationPayload.addTargetContentId("myTargetContentId");
59+
60+
JSONObject payload = pushNotificationPayload.getPayload();
61+
JSONObject aps = payload.getJSONObject("aps");
62+
assertThat(aps.getString("target-content-id"), is("myTargetContentId"));
63+
64+
}
65+
3266
}

0 commit comments

Comments
 (0)