ios push java_【iOS】push通知(JavaEE实现)

public class ApplePush extendsThread {privatePushNotificationManager pushNotificationManager;privateAppleNotificationServer appleNotificationServer;private ArrayListdevices;privatePayload payload;privateAPNSFeedBack feedBack;static public voidmain(String argc[])

{try{

String tokenDevice= "0b307cfe5d55a3018f281d68afb7ae188c102628b441587e526707fd41e62125";

PushNotificationPayload payload= newPushNotificationPayload();

payload.addAlert("大家好啊");

ArrayList devicesString = new ArrayList();

devicesString.add(tokenDevice);

ApplePush push= newApplePush();

push.sendNotification(devicesString, payload,newAPNSFeedBack() {

@Overridepublic voidAPNSFeedBack(Boolean success, Exception exception) {if(success) {

System.out.println("请求成功");

}else{

System.out.println("请求失败 exception = " +exception);

}

}

});

System.out.println("正在push中…");

}catch(Exception exception)

{

System.out.println("Json库加载失败");

}

}public Boolean sendNotification(ArrayListdevicesString,PushNotificationPayload payload,APNSFeedBack feedBack)

{//初始化

try{

String p12Path= "/Users/WangHeShiDai/Desktop/PushKey.p12"; //证书路径

String password = "wangheshidai"; //密码

Boolean isDeveloper = true; //是不是开发模式

if (devicesString == null || devicesString.size() == 0)

{

feedBack.APNSFeedBack(false,new Exception("设备惟一标识异常"));

}//构建Device

this.devices = new ArrayList(devicesString.size());for (int i = 0 ; i < devicesString.size() ; i ++)

{

String deviceString=devicesString.get(i);

Device device= newBasicDevice();

device.setToken(deviceString);this.devices.add(device);

}//保存句柄

this.payload =payload;this.feedBack =feedBack;//push管理程序

this.pushNotificationManager = newPushNotificationManager();//初始化证书和端口

this.appleNotificationServer = new AppleNotificationServerBasicImpl(p12Path,password,!isDeveloper);this.start();

}catch(Exception ex)

{

System.out.print("抛出异常");

ex.printStackTrace();

feedBack.APNSFeedBack(false,ex);

}return true;

}

@Overridepublic voidrun() {try{//连接苹果服务器

this.pushNotificationManager.initializeConnection(this.appleNotificationServer);//发送消息

this.pushNotificationManager.sendNotifications(this.payload, this.devices);//断开链接

this.pushNotificationManager.stopConnection();

System.out.println("发送成功");this.feedBack.APNSFeedBack(true,null);

}catch(Exception exception)

{

System.out.print("抛出异常");

exception.printStackTrace();this.feedBack.APNSFeedBack(false,exception);

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值