Skip to content

Commit 8ce4527

Browse files
author
Javen
committed
v2 API to support MPNs push.
1 parent f4aec41 commit 8ce4527

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

src/cn/jpush/api/common/DeviceEnum.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
public enum DeviceEnum {
44

55
Android("android"),
6-
7-
IOS("ios");
6+
IOS("ios"),
7+
MPNS("mpns");
88

99
private final String value;
1010

src/cn/jpush/api/examples/JPushClientExample.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package cn.jpush.api.examples;
22

3+
import java.util.HashMap;
4+
import java.util.Map;
5+
36
import org.slf4j.Logger;
47
import org.slf4j.LoggerFactory;
58

69
import cn.jpush.api.JPushClient;
710
import cn.jpush.api.common.DeviceEnum;
811
import cn.jpush.api.push.CustomMessageParams;
912
import cn.jpush.api.push.MessageResult;
13+
import cn.jpush.api.push.NotificationParams;
1014
import cn.jpush.api.push.ReceiverTypeEnum;
1115
import cn.jpush.api.report.ReceivedsResult;
1216

@@ -24,9 +28,23 @@ public class JPushClientExample {
2428

2529
public static void main(String[] args) {
2630
testSend();
31+
testSendMpnsNotificaiton();
2732
testGetReport();
2833
}
29-
34+
35+
private static void testSendMpnsNotificaiton() {
36+
JPushClient jpushClient = new JPushClient(masterSecret, appKey, 0, DeviceEnum.MPNS, false);
37+
NotificationParams params = new NotificationParams();
38+
params.setReceiverType(ReceiverTypeEnum.TAG);
39+
params.setReceiverValue(tag);
40+
params.setMpnsNotificationTitle(msgTitle);
41+
42+
Map<String, Object> extras = new HashMap<String, Object>();
43+
extras.put(NotificationParams.MPNS_EXTRA_OPEN_PAGE, "MainPage.xaml");
44+
45+
MessageResult msgResult = jpushClient.sendNotification(msgContent, params, extras);
46+
}
47+
3048
private static void testSend() {
3149
JPushClient jpushClient = new JPushClient(masterSecret, appKey, 0, DeviceEnum.Android, false);
3250
CustomMessageParams params = new CustomMessageParams();

src/cn/jpush/api/push/IosExtras.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ public IosExtras(int badge) {
2323
*/
2424
private int badge = 0;
2525

26-
/*
27-
* 当前软件里面的所拥有的铃声名称(如:message.wav)。
28-
* 不设置,手机默认通知铃声
29-
*/
3026
private String sound = "";
3127

3228
public int getBadge() {
@@ -46,3 +42,4 @@ public void setSound(String sound) {
4642
}
4743

4844
}
45+

src/cn/jpush/api/push/NotificationParams.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55

66
import cn.jpush.api.utils.StringUtils;
77

8-
/*
9-
* 通知内容
10-
*/
118
public class NotificationParams extends MessageParams {
129
public static final int DEFAULT_N_BUILDER_ID = 0;
1310

11+
public static final String MPNS_EXTRA_OPEN_PAGE = "_open_page";
12+
1413
public class NotificationContent extends MessageParams.MsgContent {
1514

1615
// Android notification builder id - default is 0
@@ -56,5 +55,9 @@ public void setAndroidNotificationTitle(String title) {
5655
this.getMsgContent().setTitle(title);
5756
}
5857

58+
public void setMpnsNotificationTitle(String title) {
59+
this.getMsgContent().setTitle(title);
60+
}
61+
5962
}
6063

src/cn/jpush/api/push/PushClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class PushClient extends BaseHttpClient {
2222
private boolean enableSSL = false;
2323
private boolean apnsProduction = false;
2424
private Set<DeviceEnum> devices = new HashSet<DeviceEnum>();
25-
25+
2626
public PushClient(String masterSecret, String appKey, long timeToLive, DeviceEnum device, boolean apnsProduction) {
2727
this.masterSecret = masterSecret;
2828
this.appKey = appKey;

0 commit comments

Comments
 (0)