ios推送 java代码
来源:互联网 发布:sql server 日志备份 编辑:程序博客网 时间:2024/05/16 14:51
import java.util.ArrayList;import java.util.List;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;import org.apache.commons.lang.StringUtils;public class ApnsSend{ public static void main(String[] args) throws Exception { // 向固定的设备发送 String deviceToken = "B5bd270c145936d9529c564f6c727de447698b01cf26ab57f90c205ca0fec793";// List<String> deviceToken = new ArrayList<String>(); //多人发送// deviveToken.add(""); //㈠设置消息内容 String alert = "ApnsSend!"; int badge = 100;//图标小红圈的数值 String sound = "default";//铃音 //㈡设置deviceToken 用户令牌 List<String> tokens = new ArrayList<String>(); tokens.add(deviceToken); //把这个令牌号放入 令牌List中 ,因为有多个客户端 会有多个令牌号// String certificatePath = "D:/certificate/证书.p12";//证书路径// String certificatePath = "D:/certificate/Push.p12";//证书路径 String certificatePath = "D:\\pushApp.p12";//证书路径 String certificatePassword = "123";//此处注意导出的证书密码不能为空因为空密码会报错 boolean sendCount = true; //true为 单人推送 flash为多人推送 //㈢将推送的内容 封装放入payLoad javaPSN提供的简单易用的通知方式 try { PushNotificationPayload payLoad = new PushNotificationPayload();//PNPayload 用来装载push内容的类?? payLoad.addAlert(alert); // 消息内容 payLoad.addBadge(badge); // iphone应用图标上小红圈上的数值 if (!StringUtils.isBlank(sound))//若为设置铃声 铃声就空缺着 { payLoad.addSound(sound);//铃音 } //㈣初始化连接APNS 验证证书 flash:表示的是产品测试推送服务 若为true:表示的是产品发布推送服务 /** *测试的服务器地址:gateway.sandbox.push.apple.com /端口2195 *产品推送服务器地址:gateway.push.apple.com / 2195 */ PushNotificationManager pushManager = new PushNotificationManager(); pushManager.initializeConnection(new AppleNotificationServerBasicImpl(certificatePath, certificatePassword, false)); List<PushedNotification> notifications = new ArrayList<PushedNotification>(); // 消息 List // ㈤发送push消息 if (sendCount) //单个推送 { Device device = new BasicDevice(); device.setToken(tokens.get(0)); //取tokens List中的第一个 token信息 PushedNotification notification = pushManager.sendNotification(device, payLoad, true); //发送消息 包括token(device) 封装好的消息内容 后面的true??? notifications.add(notification); //将消息加入 notifications List } else // 群推送 { List<Device> device = new ArrayList<Device>(); //建一个 List来存放 群组的token信息 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();//断开连接 System.out.println("成功发送:"+successful); System.out.println("未发送 :"+failed); } catch (Exception e) { e.printStackTrace(); } }}
0 0
- ios推送 java代码
- iOS推送的Java后台代码
- ios推送代码
- IOS 推送服务端代码
- IOS 推送代码
- java服务推送ios环境配置及java服务代码
- Java发送ios推送消息(APN)的代码示例
- IOS 推送 + java 服务端
- ios java消息推送
- java实现ios推送
- IOS推送之PHP代码
- IOS推送之PHP代码
- iOS远程推送代码分析
- IOS原生代码实现推送
- iOS:APNS推送主要代码
- 极光推送-JAVA服务器端推送代码
- iphone推送 java代码实现
- 极光推送JAVA代码示例
- Android Camera CameraHal.cpp 分析
- struts2 interceptor small demo
- Android的binder机制分析
- 头文件中包含const与非const对象
- 怎么传文件到虚拟机与共享文件夹的方法------vmware版本的虚拟机
- ios推送 java代码
- Android OMAP4 Ducati 和 OpenMax IL介绍
- sqlite3中的数据
- delphi中WEBBrowser网页JS函数调用delphi函数
- C++内联(inline)函数
- Android Camera数据流分析全程记录(overlay方式二)
- httpclient模拟登陆,不支持https的问题
- 用SQL语句添加删除修改字段
- 解读Android 4.0 Camera原生应用程序的设计思路