直接上Demo

import java.util.ArrayList;
import java.util.List; import org.apache.commons.lang3.StringUtils; import javapns.devices.Device;
import javapns.devices.implementations.basic.BasicDevice;
import javapns.notification.AppleNotificationServerBasicImpl;
import javapns.notification.PushNotificationManager;
import javapns.notification.PushNotificationPayload;
import javapns.notification.PushedNotification; public class PushPNS { public static void main(String[] args) throws Exception { // 设备的 Token 值
String deviceToken = "4f9e701ce3cb47173e3b3da5cdeb677297157b6be616689677e8e13c9b9ae652";
// push的内容
String alert = "我的push测试";
// 图标小红圈的数值
int badge = 1;
// 铃音
String sound = "default"; List<String> tokens = new ArrayList<String>();
tokens.add(deviceToken); // 推送证书的路径
String certificatePath = "/Users/ivy/Desktop/Duke/Eclipse/JinanLine/WebContent/acer.p12";
// 证书的密码
String certificatePassword = "123456";// 此处注意导出的证书密码不能为空因为空密码会报错
boolean sendCount = true; try { PushNotificationPayload payLoad = new PushNotificationPayload();
payLoad.addAlert(alert); // 消息内容
payLoad.addBadge(badge); // iphone应用图标上小红圈上的数值、 if (!StringUtils.isBlank(sound)) {
payLoad.addSound(sound); // 铃音
}
PushNotificationManager pushManager = new PushNotificationManager();
// true:表示的是产品发布推送服务 false:表示的是产品测试推送服务
pushManager
.initializeConnection(new AppleNotificationServerBasicImpl(
certificatePath, certificatePassword, false));
List<PushedNotification> notifications = new ArrayList<PushedNotification>();
// 发送push消息
if (sendCount) { Device device = new BasicDevice();
device.setToken(tokens.get(0));
PushedNotification notification = pushManager.sendNotification(
device, payLoad, true);
notifications.add(notification);
}
else { List<Device> device = new ArrayList<Device>(); for (String token : tokens) { device.add(new BasicDevice(token));
} notifications = pushManager.sendNotifications(payLoad, device);
}
List<PushedNotification> failedNotifications = PushedNotification
.findFailedNotifications(notifications);
List<PushedNotification> successfulNotifications = PushedNotification
.findSuccessfulNotifications(notifications);
int failed = failedNotifications.size();
int successful = successfulNotifications.size(); pushManager.stopConnection();
}
catch (Exception e) { e.printStackTrace();
}
}
}
  • 需要导入的包

bcprov-jdk15on-151.jar
commons-lang3-3.1.jar
JavaPNS_2.2.jar
log4j-1.2.17.jar

  • demo链接

http://files.cnblogs.com/files/duke-cui/Apns.zip

IOS 基于APNS消息推(JAVA后台)的更多相关文章

  1. IOS 基于APNS消息推送原理与实现(JAVA后台)

    Push的原理: Push 的工作机制可以简单的概括为下图 图中,Provider是指某个iPhone软件的Push服务器,这篇文章我将使用.net作为Provider. APNS 是Apple Pu ...

  2. 转:IOS 基于APNS消息推送原理与实现(JAVA后台)

    Push的原理: Push 的工作机制可以简单的概括为下图   图中,Provider是指某个iPhone软件的Push服务器,这篇文章我将使用.net作为Provider. APNS 是Apple ...

  3. IOS 基于APNS消息推送原理与实现(JAVA后台)--转

    Push的原理: Push 的工作机制可以简单的概括为下图   图中,Provider是指某个iPhone软件的Push服务器,这篇文章我将使用.net作为Provider. APNS 是Apple ...

  4. iOS 基于APNS消息推送原理与实现(包括JAVA后台代码)

    Push的原理: Push 的工作机制可以简单的概括为下图   图中,Provider是指某个iPhone软件的Push服务器,这篇文章我将使用.net作为Provider. APNS 是Apple ...

  5. 基于APNs最新HTTP/2接口实现iOS的高性能消息推送(服务端篇)

    1.前言 本文要分享的消息推送指的是当iOS端APP被关闭或者处于后台时,还能收到消息/信息/指令的能力. 这种在APP处于后台或关闭情况下的消息推送能力,通常在以下场景下非常有用: 1)IM即时通讯 ...

  6. 基于C++ 苹果apns消息推送实现(2)

    1.该模块的用途C++ 和 Openssl 代码 它实现了一个简单的apns顾客 2.配套文件:基于boost 的苹果apns消息推送实现(1) 3.最初使用的sslv23/sslv2/sslv3仅仅 ...

  7. oc学习之路----APNS消息推送从证书到代码(2015年4月26号亲试可用)

    前言:看这篇博客之前要准备:首先的有一个99刀的个人开发者账号或者199刀的企业开发者账号,其次你用的是apns消息推送,(本人之前四处打听有没有其他消息推送的方法:收获如下:首先如果想做到apns的 ...

  8. (转)在SAE使用Apple Push Notification Service服务开发iOS应用, 实现消息推送

    在SAE使用Apple Push Notification Service服务开发iOS应用, 实现消息推送 From: http://saeapns.sinaapp.com/doc.html 1,在 ...

  9. Push:iOS基于APNS的消息推送

    1. Push的三个步骤,如下图所示: (1)Push服务应用程序把要发送的消息.目的iPhone的标识打包,发给APNS: (2)APNS在自身的已注册Push服务的iPhone列表中,查找有相应标 ...

随机推荐

  1. MySQL常用的一些语句,索引,字段等

    1.库相关:建库:character set:指定编码COLLATE:排序规则 utf8mb4_general_ci 大小写不敏感CREATE DATABASE `test_db` default c ...

  2. 安装php时,configure: error: xml2-config not found. Please check your libxml2 installation

    参考文章:http://blog.csdn.net/anljf/article/details/6981247 安装php时的报错configure: error: xml2-config not f ...

  3. Asp.Net Core 第07局:路由

    总目录 前言 本文介绍Asp.Net Core 路由. 环境 1.Visual Studio 2017 2.Asp.Net Core 2.2 开局 第一手:路由概述 1.路由主要用于处理特定的请求. ...

  4. 非常全的Linux基础知识点

    Linux是每个后端程序员必须要掌握的系统,今天小编就给你分享一篇Linux基础知识点大全,看看你知道多少? 一. 从认识操作系统开始 1.1 操作系统简介 我通过以下四点介绍什么操作系统: 操作系统 ...

  5. Linux(Ubuntu)常用命令(一)

    Linux先知: Linux历史: 关于这个我就不再多说了,其实是一个很有意思的故事串,网上找下一大堆. 类Unix系统目录结构: ubuntu没有盘符这个概念,只有一个根目录/,所有文件都在它下面 ...

  6. taintCheck的实现

    参考:http://bitblaze.cs.berkeley.edu/papers/taintcheck-full.pdf 1. 应用taint analysis需要解决三个问题 a. 哪些input ...

  7. jsbridge 原理

    https://juejin.im/post/5abca877f265da238155b6bc

  8. Redis测试类

    单机&集群安装: https://blog.csdn.net/zxd1435513775/article/details/88901992 安装5.0.4版本OK,5.0.5版本make时报错 ...

  9. 【怒转】 idea快捷键说明大全(中英文对照)

    1 编辑[Editing] 快捷键 英文说明 中文说明 Ctrl + Space Basic code completion (the name of any class, method or var ...

  10. Moco 框架以及其在 Web 集成测试的应用

    转自:https://www.ibm.com/developerworks/cn/web/1405_liugang_mocowebtest/ Moco 框架以及其在 Web 集成测试的应用 我们往往将 ...