server端向ios push消息代码
来源:互联网 发布:宇航数控仿真软件 编辑:程序博客网 时间:2024/04/24 12:42
方式1:
package apple.push;
import java.util.LinkedList;
import java.util.ListIterator;
import javapns.back.FeedbackServiceManager;
import javapns.back.PushNotificationManager;
import javapns.back.SSLConnectionHelper;
import javapns.data.Device;
import javapns.data.PayLoad;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
send();
//feedback();
}
public static void send(){
try
{
PushNotificationManager pushManager = PushNotificationManager.getInstance();
pushManager.initializeConnection(
"gateway.push.apple.com",
2195,
"c:/apple_push.p12",
"111111", SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
// Link iPhone’s UDID
pushManager.addDevice("my_iPhone", "0000000000000000000000000000000000000000");
PayLoad localPayLoad1 = new PayLoad();
localPayLoad1.addAlert("My alert message测试");
localPayLoad1.addBadge(36);
localPayLoad1.addSound("default");
Device localDevice = PushNotificationManager.getInstance().getDevice("my_iPhone");
pushManager.sendNotification(localDevice, localPayLoad1);
pushManager.stopConnection();
}
catch (Exception localException)
{
localException.printStackTrace();
}
}
public static void feedback(){
try
{
FeedbackServiceManager feedbackManager = FeedbackServiceManager.getInstance();
LinkedList<Device> devices = feedbackManager.getDevices("feedback.push.apple.com", 2196,
"/home/ubuntu/mypush.p12", "password", SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
// Display total devices returned
System.out.println( "Devices returned: " + devices.size() );
// Iterate over all returned devices and display each
ListIterator<Device> itr = devices.listIterator();
while ( itr.hasNext() ) {
System.out.println( itr.next() );
}
}
catch (Exception localException)
{
localException.printStackTrace();
}
}
}
方式2:
public static void main(String[] args){
String keystore = "D:/XXXXXXXX/XXX.p12";//证书路径和证书名
String password = "XXXXXXXX"; // 证书密码
String token = "XXXXXX XXXXXX XXXXXX XXXXXX XXXXXX XXXXXX XXXXXX XXXXXX";// 手机唯一标识
boolean production = true; // 设置true为正式服务地址,false为开发者地址
int threadThreads = 10; // 线程数
try {
// 建立与Apple服务器连接
AppleNotificationServer server = new AppleNotificationServerBasicImpl(keystore, password, production );
List<PayloadPerDevice> list = new ArrayList<PayloadPerDevice>();
PushNotificationPayload payload = new PushNotificationPayload();
payload.addAlert("推送内容");
payload.addSound("default");// 声音
payload.addBadge(1);//图标小红圈的数值
payload.addCustomDictionary("url","www.baidu.com");// 添加字典
PayloadPerDevice pay = new PayloadPerDevice(payload,token);// 将要推送的消息和手机唯一标识绑定
list.add(pay);
NotificationThreads work = new NotificationThreads(server,list,threadThreads);//
work.setListener(DEBUGGING_PROGRESS_LISTENER);// 对线程的监听,一定要加上这个监听
work.start(); // 启动线程
work.waitForAllThreads();// 等待所有线程启动完成
} catch (Exception e) {
e.printStackTrace();
}
}
// 线程监听
public static final NotificationProgressListener DEBUGGING_PROGRESS_LISTENER = new NotificationProgressListener() {
public void eventThreadStarted(NotificationThread notificationThread) {
System.out.println(" [EVENT]: thread #" + notificationThread.getThreadNumber() + " started with " + " devices beginning at message id #" + notificationThread.getFirstMessageIdentifier());
}
public void eventThreadFinished(NotificationThread thread) {
System.out.println(" [EVENT]: thread #" + thread.getThreadNumber() + " finished: pushed messages #" + thread.getFirstMessageIdentifier() + " to " + thread.getLastMessageIdentifier() + " toward "+ " devices");
}
public void eventConnectionRestarted(NotificationThread thread) {
System.out.println(" [EVENT]: connection restarted in thread #" + thread.getThreadNumber() + " because it reached " + thread.getMaxNotificationsPerConnection() + " notifications per connection");
}
public void eventAllThreadsStarted(NotificationThreads notificationThreads) {
System.out.println(" [EVENT]: all threads started: " + notificationThreads.getThreads().size());
}
public void eventAllThreadsFinished(NotificationThreads notificationThreads) {
System.out.println(" [EVENT]: all threads finished: " + notificationThreads.getThreads().size());
}
public void eventCriticalException(NotificationThread notificationThread, Exception exception) {
System.out.println(" [EVENT]: critical exception occurred: " + exception);
}
};
- server端向ios push消息代码
- 消息推送(Server Push)
- 向github上push代码
- 通过SSH向GitHub push代码
- ios开发:UINavigationController反方向滑动push
- IOS Push消息推送原理及应用
- IOS Push消息推送原理及应用
- python 发送 iOS APNS push 消息
- VC实现 IOS后台消息PUSH
- 服务器向ios推送消息
- Java 向ios推送消息
- ios push server wrote by php
- IOS push(C语言代码)
- 给iOS程序添加push代码
- Git Push(向远程Github提交本地代码)
- 利用git push向服务器一键部署代码
- github向远程push代码遇到的一些问题
- java向IOS设备推送消息
- linux并发控制之顺序锁
- OSCache 学习笔记(2)__缓存整个页面 & 缓存局部页面
- 帮助你如何迅速优化你MySQL数据库性能
- Android客户端捕获http请求包的方法【转】
- 深入解读PHP类phpExcel应用
- server端向ios push消息代码
- session获取方法
- MySQL分表优化试验
- 常见vc 6.0错误解决办法(逐渐增加)
- YII入门教程第二章
- 转 C++中各种类型的成员变量的初始化方法
- [360] 告诉我这个结果是什么? [值得思考的问题]
- 年少轻狂的季节
- httpclient自动获取页面编码设置进行字符编码,使httpclient适用所有网页抓取不乱码