利用javapns对IOS进行推送
start
package com.jynine.javapns; import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties; import javapns.Push;
import javapns.communication.exceptions.CommunicationException;
import javapns.communication.exceptions.KeystoreException;
import javapns.devices.Device;
import javapns.devices.Devices;
import javapns.notification.PayloadPerDevice;
import javapns.notification.PushNotificationPayload;
import javapns.notification.transmission.PushQueue; import org.apache.commons.lang.StringUtils;
import org.json.JSONException; public class IosPushUtil {
public static String keystore = null;
public static String password = null;
public static String host = null;
public static Boolean production = true;//true:production false: sandbox
public static final int numberOfThreads = 8;
static{
Properties propertie = new Properties();
InputStream inputStream; try {
inputStream = IosPushUtil.class.getClassLoader()
.getResourceAsStream("push.properties");
propertie.load(inputStream);
keystore = propertie.getProperty("certificatePath");
password = propertie.getProperty("certificatePassword","123456");
host = propertie.getProperty("host","gateway.push.apple.com");
production = Boolean.valueOf(propertie.getProperty("production", "true"));
inputStream.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
//pushMsgNotification("hello!!!2", true, "iostoken");
// pushBadgeNotification(1, "iostoken");
String[] devs= new String[10000];
for (int i = 0; i < devs.length; i++) {
devs[i] = "iostoken";
}
List<Device> devices=Devices.asDevices(devs);
System.out.println(devices.size());
//pushPayLoadByThread(devices, "Hello 2222222", 1, null, null);
//pushPayloadDevicePairs(devices, "Hello 111111111", 1, null, null);
//pushPayloadDevicePairs(devices, "Hello +++", 1, null, null);
queue(devices,"Hello 2222222", 1, null, null);
}
/**
* 推送一个简单消息
* @param msg 消息
* @param devices 设备
* @throws CommunicationException
* @throws KeystoreException
*/
public static void pushMsgNotification(String msg,Object devices) throws CommunicationException, KeystoreException{
Push.alert(msg, keystore, password, production, devices);
}
/**
* 推送一个标记
* @param badge 标记
* @param devices 设备
* @throws CommunicationException
* @throws KeystoreException
*/
public static void pushBadgeNotification(int badge,Object devices) throws CommunicationException, KeystoreException{
Push.badge(badge, keystore, password, production, devices);
}
/**
* 推送一个语音
* @param sound 语音
* @param devices 设备
* @throws CommunicationException
* @throws KeystoreException
*/
public static void pushSoundNotification(String sound,Object devices) throws CommunicationException, KeystoreException{
Push.sound(sound, keystore, password, production, devices);
}
/**
* 推送一个alert+badge+sound通知
* @param message 消息
* @param badge 标记
* @param sound 声音
* @param devices 设备
* @throws CommunicationException
* @throws KeystoreException
*/
public static void pushCombinedNotification(String message,int badge,String sound,Object devices) throws CommunicationException, KeystoreException{
Push.combined(message, badge, sound, keystore, password, production, devices);
}
/**
* 通知Apple的杂志内容
* @param devices 设备
* @throws CommunicationException
* @throws KeystoreException
*/
public static void contentAvailable(Object devices) throws CommunicationException, KeystoreException{
Push.contentAvailable(keystore, password, production, devices);
}
/**
* 推送有用的调试信息
* @param devices 设备
* @throws CommunicationException
* @throws KeystoreException
*/
public static void test(Object devices) throws CommunicationException, KeystoreException{
Push.test(keystore, password, production, devices);
}
/**
* 推送自定义负载
* @param devices
* @param msg
* @param badge
* @param sound
* @param map
* @throws JSONException
* @throws CommunicationException
* @throws KeystoreException
*/
public static void pushPayload(List<Device> devices, String msg,Integer badge,String sound,Map<String,String> map) throws JSONException, CommunicationException, KeystoreException{
PushNotificationPayload payload = customPayload(msg, badge, sound, map);
Push.payload(payload, keystore, password, production, devices);
}
/**
* 用内置线程推送负载信息
* @param devices
* @param msg
* @param badge
* @param sound
* @param map
* @throws Exception
*/
public static void pushPayLoadByThread(List<Device> devices, String msg,Integer badge,String sound,Map<String,String> map) throws Exception{
PushNotificationPayload payload = customPayload(msg, badge, sound, map);
Push.payload(payload, keystore, password, production, numberOfThreads, devices);
}
/**
* 推送配对信息
* @param devices
* @param msg
* @param badge
* @param sound
* @param map
* @throws JSONException
* @throws CommunicationException
* @throws KeystoreException
*/
public static void pushPayloadDevicePairs(List<Device> devices,String msg,Integer badge,String sound,Map<String,String> map) throws JSONException, CommunicationException, KeystoreException{
List<PayloadPerDevice> payloadDevicePairs = new ArrayList<PayloadPerDevice>();
PayloadPerDevice perDevice = null;
for (int i = 0; i <devices.size(); i++) {
perDevice = new PayloadPerDevice(customPayload(msg+"--->"+i, badge, sound, map), devices.get(i));
payloadDevicePairs.add(perDevice);
}
Push.payloads(keystore, password, production, payloadDevicePairs);
}
/**
* 用线程推配对信息
* @param devices
* @param msg
* @param badge
* @param sound
* @param map
* @throws Exception
*/
public static void pushPayloadDevicePairsByThread(List<Device> devices,String msg,Integer badge,String sound,Map<String,String> map) throws Exception{
List<PayloadPerDevice> payloadDevicePairs = new ArrayList<PayloadPerDevice>();
PayloadPerDevice perDevice = null;
for (int i = 0; i <devices.size(); i++) {
perDevice = new PayloadPerDevice(customPayload(msg+"--->"+i, badge, sound, map), devices.get(i));
payloadDevicePairs.add(perDevice);
}
Push.payloads(keystore, password, production,numberOfThreads, payloadDevicePairs);
}
/**
* 队列多线程推送
* @param devices
* @param msg
* @param badge
* @param sound
* @param map
* @throws KeystoreException
* @throws JSONException
*/
public static void queue(List<Device> devices,String msg,Integer badge,String sound,Map<String,String> map) throws KeystoreException, JSONException{
PushQueue queue = Push.queue(keystore, password, production, numberOfThreads);
queue.start();
PayloadPerDevice perDevice = null;
for (int i = 0; i <devices.size(); i++) {
perDevice = new PayloadPerDevice(customPayload(msg+"--->"+i, badge, sound, map), devices.get(i));
queue.add(perDevice);
}
}
/**
* 自定义负载
* @param msg
* @param badge
* @param sound
* @param map 自定义字典
* @return
* @throws JSONException
*/
private static PushNotificationPayload customPayload(String msg,Integer badge,String sound,Map<String,String> map) throws JSONException{
PushNotificationPayload payload = PushNotificationPayload.complex();
if(StringUtils.isNotEmpty(msg)){
payload.addAlert(msg);
}
if(badge != null){
payload.addBadge(badge);
}
payload.addSound(StringUtils.defaultIfEmpty(sound, "default"));
if(map!=null && !map.isEmpty()){
Object[] keys = map.keySet().toArray();
Object[] vals = map.values().toArray();
if(keys!= null && vals != null && keys.length == vals.length){
for (int i = 0; i < map.size(); i++) {
payload.addCustomDictionary(String.valueOf(keys[i]),String.valueOf(vals[i]));
}
}
}
return payload;
}
}
利用javapns对IOS进行推送的更多相关文章
- iOS远程推送原理及实现过程
➠更多技术干货请戳:听云博客 推送通知,是现在的应用必不可少的功能.那么在 iOS 中,我们是如何实现远程推送的呢?iOS 的远程推送原理又是什么呢?在做 iOS 远程推送时,我们会遇到各种各样的问题 ...
- (七十三)iOS本地推送通知的实现
iOS的推送通知分为本地推送和网络推送两种,如果App处于挂起状态,是可以发送本地通知的,如果已经被杀掉,则只有定时通知可以被执行,而类似于QQ的那种网络消息推送就无法实现了,因为App的网络模块在被 ...
- 【转】iOS消息推送实现过程记录
客户端代码:链接地址 服务器代码:链接地址 链接地址 这里记录下iOS消息推送实现的全过程 首先,申请秘钥. 之后进入链接地址开发者,当然你得有啊!!!!! 点击这里 如图: 下面实现创建推送证书( ...
- (转)OpenFire源码学习之十八:IOS离线推送
转:http://blog.csdn.net/huwenfeng_2011/article/details/43458213 IOS离线推送 场景: 如果您有iOS端的APP,在会话聊天的时候,用户登 ...
- 使用PushSharp给iOS应用推送消息
PushSharp是一个C#编写的服务端类库,用于推送消息到各种客户端,支持iOS(iPhone/iPad).Android.Windows Phone.Windows 8.Amazo.Blackbe ...
- IOS远程推送
IOS远程推送 一.关于推送通知 推送通知,也被叫做远程通知,是在iOS 3.0以后被引入的功能.是当程序没有启动或不在前台运行时,告诉用户有新消息的一种途径,是从外部服务器发送到应用程序上的.一般说 ...
- iOS 消息推送(APNs) 傻瓜式教程
也可以去我的简书页面查看这篇文章 首先: 1.做iOS消息推送需要真机测试 2.做iOS消息推送需要有付费的开发者账号 是否继续看帖? 先学习一下相关的知识吧! 因为中途可能会遇到一些问题,这篇文章或 ...
- (转载)iOS 极光推送SDK 集成指南
iOS SDK 集成指南 使用提示 本文匹配的 SDK版本:r1.2.5 以后. 查看最近更新了解最新的SDK更新情况. 产品功能说明 极光推送(JPush)是一个端到端的推送服务,使得服务器端消息能 ...
- iOS极光推送,两次Bundleid不一致( 开发证书没有通过验证 是否重新上传证书)的解决方案
极光在配置ios端推送时,需要上传p12证书,如果遇到如下图:: 证书上传未通过的原因一般有: 1.当前上传的p12证书密码输入有误: 2. 证书导出的时候展开了证书,把个人私钥导了出来,导证书的时候 ...
随机推荐
- oracle中extract()函数----用于截取年、月、日、时、分、秒
oracle中extract()函数从oracle 9i中引入,用于从一个date或者interval类型中截取到特定的部分 语法如下: extract ( { year | month | day ...
- RHEL7 配置临时IP 测试
RHEL7 配置或添加临时IP地址测试: [root@rhel7 Desktop]# ip a s enp0s3 ---查看原网卡IP 为192.168.1.7 : enp0s3: <BROAD ...
- MessageListActivity has leaked IntentReceiver
1. 在MessagelistActivity中出现has leaked IntentReceiver的异常.异常日志如下. 07-15 08:09:53.211: E/ActivityThread( ...
- BOM介绍
BOM 浏览器对象模型 BOM (Browser Object Model,浏览器对象模型)提供了通过 JavaScript 访问和控制浏览器窗口(window).显示器(screen)与浏览历史(h ...
- numpy二分查找
a = np.array([1, 2, 2, 3]) print(np.searchsorted(a, 0)) # 0 print(np.searchsorted(a, 1)) # 0 print(n ...
- ruby的sort方法的重新认识
ruby中的sort方法,这个方法可以加一个两个参数的block,这个block可以返回1 0 -1来表示这两个参数大于 等于 小于示例: str = ["192.160.175" ...
- 联想Thinkpad笔记本自带win10改win7图文教程
一.准备工作: 1.备份转移硬盘所有文件 2.改装win7将删除所有分区,要恢复预装的win10系统需到售后 3.4G空间以上U盘,制作U盘PE启动盘 4.操作系统:联想Lenovo笔记本专用GHOS ...
- 【Spring】spring的7个模块
Spring 是一个开源框架,是为了解决企业应用程序开发复杂性而创建的.框架的主要优势之一就是其分层架构,分层架构允许您选择使用哪一个组件,同时为 J2EE 应用程序开发提供集成的框架. Spring ...
- C# Httpclient客户端操作
原文地址:https://www.cnblogs.com/Xujg/p/4113387.html HttpClient 当前主流用法,异步请求,自.NET4.5开始可从Nuget包管理中获取. usi ...
- Docker stop停止/remove删除所有容器
原文地址:https://blog.csdn.net/superdangbo/article/details/78688904 docker ps // 查看所有正在运行容器$ docker stop ...