IOS 基于APNS消息推(JAVA后台)
直接上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后台)的更多相关文章
- IOS 基于APNS消息推送原理与实现(JAVA后台)
Push的原理: Push 的工作机制可以简单的概括为下图 图中,Provider是指某个iPhone软件的Push服务器,这篇文章我将使用.net作为Provider. APNS 是Apple Pu ...
- 转:IOS 基于APNS消息推送原理与实现(JAVA后台)
Push的原理: Push 的工作机制可以简单的概括为下图 图中,Provider是指某个iPhone软件的Push服务器,这篇文章我将使用.net作为Provider. APNS 是Apple ...
- IOS 基于APNS消息推送原理与实现(JAVA后台)--转
Push的原理: Push 的工作机制可以简单的概括为下图 图中,Provider是指某个iPhone软件的Push服务器,这篇文章我将使用.net作为Provider. APNS 是Apple ...
- iOS 基于APNS消息推送原理与实现(包括JAVA后台代码)
Push的原理: Push 的工作机制可以简单的概括为下图 图中,Provider是指某个iPhone软件的Push服务器,这篇文章我将使用.net作为Provider. APNS 是Apple ...
- 基于APNs最新HTTP/2接口实现iOS的高性能消息推送(服务端篇)
1.前言 本文要分享的消息推送指的是当iOS端APP被关闭或者处于后台时,还能收到消息/信息/指令的能力. 这种在APP处于后台或关闭情况下的消息推送能力,通常在以下场景下非常有用: 1)IM即时通讯 ...
- 基于C++ 苹果apns消息推送实现(2)
1.该模块的用途C++ 和 Openssl 代码 它实现了一个简单的apns顾客 2.配套文件:基于boost 的苹果apns消息推送实现(1) 3.最初使用的sslv23/sslv2/sslv3仅仅 ...
- oc学习之路----APNS消息推送从证书到代码(2015年4月26号亲试可用)
前言:看这篇博客之前要准备:首先的有一个99刀的个人开发者账号或者199刀的企业开发者账号,其次你用的是apns消息推送,(本人之前四处打听有没有其他消息推送的方法:收获如下:首先如果想做到apns的 ...
- (转)在SAE使用Apple Push Notification Service服务开发iOS应用, 实现消息推送
在SAE使用Apple Push Notification Service服务开发iOS应用, 实现消息推送 From: http://saeapns.sinaapp.com/doc.html 1,在 ...
- Push:iOS基于APNS的消息推送
1. Push的三个步骤,如下图所示: (1)Push服务应用程序把要发送的消息.目的iPhone的标识打包,发给APNS: (2)APNS在自身的已注册Push服务的iPhone列表中,查找有相应标 ...
随机推荐
- JS获取浏览器地址栏的多参数值的任意值
常用的几个方法就不讲了,这里我用的是两个方法组 使用方法是: getParamValue("id"); http://localhost:2426/TransactionNotes ...
- 实现自己的shell--MIT xv6 shell
参考代码: #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <fcnt ...
- vim中 E212:无法打开并写入文件 的解决办法
因为centos7刚安装的时候是无法上网的,所以,需要去配置一下ifcfg-ens33文件,但实际上这个文件是只读的文件,root也无法去更改内容,这时候保存的时候需要使用 w ! sudo tee ...
- web测试点
一.输入框 1.字符型输入框: (1)字符型输入框:英文全角.英文半角.数字.空或者空格.特殊字符“~!@#¥%……&*?[]{}”特别要注意单引号和&符号. 禁止直接输入特殊字符时, ...
- 数论---lcm和gcd
cd即最大公约数,lcm即最小公倍数. 首先给出a×b=gcd×lcm 证明:令gcd(a,b)=k,a=xk,b=yk,则a×b=xykk,而lcm=xyk,所以ab=gcd*lcm. 所以求lcm ...
- upc组队赛16 Melody【签到水】
Melody 题目描述 YellowStar is versatile. One day he writes a melody A = [A1, ..., AN ], and he has a sta ...
- js设置cookies
//写入cookies的方法 function setCookie(name, value, seconds) { seconds = seconds || 0; //seconds有值就直接赋值,没 ...
- 利用单臂路由实现VLAN间路由(有1个疑问)
配置PC机: PC1:IP 192.168.1.1 :掩码:255.255.255.0:网关:192.168.1.254 VLAN 10 PC2:IP 192.168.2.1 :掩码:255.255 ...
- javascript中数组的应用总结
最近在总结javascript的相关应用,今天对js中的数组部分进行归纳总结,以便在以后的工作中有所参考. 1.在js中数组的定义方式有两种: var a = [1,2,3,4]; var b = n ...
- xterm.js的深入学习
demo <template> <div id="app" class="app-box">Hello</div> < ...