Skip to content

Commit 669cade

Browse files
author
Javen
committed
Add more comments
1 parent b5a59f5 commit 669cade

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@
1010
import com.google.gson.JsonObject;
1111
import com.google.gson.JsonPrimitive;
1212

13+
/**
14+
* APNs 通知类
15+
* <p>
16+
* 支持 APNs 默认的几个参数:
17+
* <li>alert: 继承自父类 PlatformNotification 的 alert 属性;本类设置则覆盖。</li>
18+
* <li>badge: 支持 setBadge(int) 方法来设置;支持 incrBadge(int) 方法来增加。</li>
19+
* <li>sound: 支持 setSound(string) 方法来设置声音文件。</li>
20+
* <li>content-available: 用来支持后台推送。如果该值赋值为 1,表示开启后台推送。</li>
21+
* <li>extras: JSON object. 支持更多的自定义字段信息。</li>
22+
* </p>
23+
* <p>
24+
* 需要特别留意的是,JPush SDK 会对以下几个值有特别的默认设置考虑:
25+
* <li>badge: 默认为 "+1"。如果需要取消 badge 值,需要显式地调用 disableBadge().</li>
26+
* <li>sound: 默认为 "",即默认的声音提示。如果需要取消 sound 值,即不要声音,需要显式地调用 disableSound(). </li>
27+
* </p>
28+
*/
1329
public class IosNotification extends PlatformNotification {
1430
public static final String NOTIFICATION_IOS = "ios";
1531

src/cn/jpush/api/push/model/notification/PlatformNotification.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package cn.jpush.api.push.model.notification;
22

3+
import java.util.Map;
4+
35
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
57

@@ -98,6 +100,7 @@ protected abstract static class Builder<T> {
98100
public abstract Builder<T> addExtra(String key, String value);
99101
public abstract Builder<T> addExtra(String key, Number value);
100102
public abstract Builder<T> addExtra(String key, Boolean value);
103+
public abstract Builder<T> addExtras(Map<String, String> extras);
101104

102105
public abstract T build();
103106
}

test/cn/jpush/api/push/remote/NotificationTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,30 @@
1111
import cn.jpush.api.push.model.notification.AndroidNotification;
1212
import cn.jpush.api.push.model.notification.Notification;
1313

14+
import com.google.gson.JsonObject;
15+
1416
public class NotificationTest extends BaseRemoteTest {
17+
18+
@Test
19+
public void sendNotification_alert_json() throws Exception {
20+
JsonObject json = new JsonObject();
21+
json.addProperty("key1", "value1");
22+
json.addProperty("key2", true);
23+
24+
String alert = json.toString();
25+
System.out.println(alert);
26+
27+
PushPayload payload = PushPayload.newBuilder()
28+
.setAudience(Audience.all())
29+
.setPlatform(Platform.all())
30+
.setNotification(Notification.newBuilder()
31+
.addPlatformNotification(AndroidNotification.newBuilder()
32+
.setAlert(alert)
33+
.setTitle("title").build()).build())
34+
.build();
35+
PushResult result = _client.sendPush(payload);
36+
assertTrue(result.isResultOK());
37+
}
1538

1639
// --------------- Android
1740

0 commit comments

Comments
 (0)