Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0332236

Browse files
committed
支持 iOS10 新特性,增加新字段
1 parent 929e7b5 commit 0332236

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

src/main/java/cn/jpush/api/push/model/notification/IosNotification.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class IosNotification extends PlatformNotification {
3535
private static final String BADGE = "badge";
3636
private static final String SOUND = "sound";
3737
private static final String CONTENT_AVAILABLE = "content-available";
38+
private static final String MUTABLE_CONTENT = "mutable-content";
39+
private static final String SUBTITLE = "subtitle";
3840
private static final String CATEGORY = "category";
3941

4042
private static final String ALERT_VALID_BADGE = "Badge number should be 0~99999, "
@@ -47,10 +49,13 @@ public class IosNotification extends PlatformNotification {
4749
private final String badge;
4850
private final boolean contentAvailable;
4951
private final String category;
52+
private final boolean mutableContent;
53+
private final String subtitle;
54+
5055

5156
private IosNotification(Object alert, String sound, String badge,
5257
boolean contentAvailable, boolean soundDisabled, boolean badgeDisabled,
53-
String category,
58+
String category, boolean mutableContent, String subtitle,
5459
Map<String, String> extras,
5560
Map<String, Number> numberExtras,
5661
Map<String, Boolean> booleanExtras,
@@ -63,6 +68,8 @@ private IosNotification(Object alert, String sound, String badge,
6368
this.soundDisabled = soundDisabled;
6469
this.badgeDisabled = badgeDisabled;
6570
this.category = category;
71+
this.mutableContent = mutableContent;
72+
this.subtitle = subtitle;
6673
}
6774

6875
public static Builder newBuilder() {
@@ -103,6 +110,13 @@ public JsonElement toJSON() {
103110
if (null != category) {
104111
json.add(CATEGORY, new JsonPrimitive(category));
105112
}
113+
if (mutableContent) {
114+
json.add(MUTABLE_CONTENT, new JsonPrimitive(1));
115+
}
116+
if (null != subtitle) {
117+
json.add(SUBTITLE, new JsonPrimitive(subtitle));
118+
}
119+
106120

107121
return json;
108122
}
@@ -115,6 +129,8 @@ public static class Builder extends PlatformNotification.Builder<IosNotification
115129
private boolean soundDisabled = false;
116130
private boolean badgeDisabled = false;
117131
private String category;
132+
private boolean mutableContent;
133+
private String subtitle;
118134

119135
protected Builder getThis() {
120136
return this;
@@ -181,10 +197,20 @@ public Builder setAlert(Object alert) {
181197
return this;
182198
}
183199

200+
public Builder setMutableContent(boolean mutableContent) {
201+
this.mutableContent = mutableContent;
202+
return this;
203+
}
204+
205+
public Builder setSubtitle(String subtitle) {
206+
this.subtitle = subtitle;
207+
return this;
208+
}
209+
184210

185211
public IosNotification build() {
186212
return new IosNotification(alert, sound, badge, contentAvailable,
187-
soundDisabled, badgeDisabled, category,
213+
soundDisabled, badgeDisabled, category, mutableContent, subtitle,
188214
extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder, jsonExtrasBuilder);
189215
}
190216
}

src/test/java/cn/jpush/api/push/PushClientTest.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package cn.jpush.api.push;
22

3-
import static cn.jpush.api.examples.PushExample.buildPushObject_ios_tagAnd_alertWithExtrasAndMessage;
43
import static org.junit.Assert.assertTrue;
54
import static org.junit.Assert.fail;
65

76
import cn.jiguang.commom.ClientConfig;
87
import cn.jpush.api.JPushClient;
98
import cn.jpush.api.examples.PushExample;
9+
import cn.jpush.api.push.model.Message;
10+
import cn.jpush.api.push.model.Options;
1011
import cn.jpush.api.push.model.Platform;
12+
import cn.jpush.api.push.model.audience.Audience;
1113
import cn.jpush.api.push.model.notification.InterfaceAdapter;
14+
import cn.jpush.api.push.model.notification.IosNotification;
15+
import cn.jpush.api.push.model.notification.Notification;
1216
import cn.jpush.api.push.model.notification.PlatformNotification;
1317
import com.google.gson.Gson;
1418
import com.google.gson.GsonBuilder;
@@ -52,6 +56,25 @@ public void testSendPush() {
5256
}
5357
}
5458

59+
private static PushPayload buildPushObject_ios_tagAnd_alertWithExtrasAndMessage() {
60+
return PushPayload.newBuilder()
61+
.setPlatform(Platform.ios())
62+
.setAudience(Audience.tag_and("tag1", "tag_all"))
63+
.setNotification(Notification.newBuilder()
64+
.addPlatformNotification(IosNotification.newBuilder()
65+
.setAlert(ALERT)
66+
.setBadge(5)
67+
.setSound("happy")
68+
.addExtra("from", "JPush")
69+
.build())
70+
.build())
71+
.setMessage(Message.content(MSG_CONTENT))
72+
.setOptions(Options.newBuilder()
73+
.setApnsProduction(true)
74+
.build())
75+
.build();
76+
}
77+
5578
@Test(expected = IllegalArgumentException.class)
5679
public void test_invalid_json() {
5780
PushClient pushClient = new PushClient(MASTER_SECRET, APP_KEY);

0 commit comments

Comments
 (0)