public void run() {
try {
PushNotificationPayload payLoad = new PushNotificationPayload();
String sound = "default";// 铃
payLoad.addAlert(message); // 消息内容
payLoad.addBadge(1); // 应用图标上小红圈上的数值
if (!StringUtils.isBlank(sound)) {
payLoad.addSound(sound);// 铃音
}
payLoad.addCustomDictionary("username", "system");
payLoad.addCustomDictionary("type", 1);
PushNotificationManager pushManager = new PushNotificationManager();
pushManager
.initializeConnection(new AppleNotificationServerBasicImpl(
p12Path, password, false));
List<PushedNotification> notifications = new ArrayList<PushedNotification>();
Device device = new BasicDevice();
device.setToken(token);
PushedNotification notification = pushManager.sendNotification(
device, payLoad, true);
notifications.add(notification);
List<PushedNotification> failedNotifications = PushedNotification
.findFailedNotifications(notifications);
List<PushedNotification> successfulNotifications = PushedNotification
.findSuccessfulNotifications(notifications);
int failed = failedNotifications.size();
int successful = successfulNotifications.size();
if (successful > 0 && failed == 0) {
System.out.println("success count \t: "
+ successfulNotifications.size());
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载