java向IOS设备推送消息

java向IOS推送消息

1:所需要jar包

 javaPNS_2.2.jar, 

bcprov-jdk16-145-1.jar,

javapns-jdk16-163.jar

2:创建证书

需要开发者网站上导出的aps_developer_identity证书和Apple Development Push Services证书进行合成,
  生成可以供Java使用的p12证书。

3:部分代码如下:

//验证
	KeystoreManager.validateKeystoreParameter("证书路径");
	AppleNotificationServer server = new AppleNotificationServerBasicImpl("证书路径", "密码", "正式或测试(true and false) ");
	KeystoreManager.verifyKeystoreContent(server, keystore);
	//推送
	PushNotificationPayload complexPayload = PushNotificationPayload.complex();
	ArrayList<String> parameters = new ArrayList<String>();
	complexPayload.addCustomAlertBody("附件");
	complexPayload.addCustomAlertActionLocKey("Open AppMail");
	complexPayload.addCustomAlertLocKey("%@[%@]%@");
	parameters.add("消息来源");
	parameters.add("标题");
	parameters.add("消息内容");
	complexPayload.addCustomAlertLocArgs(parameters);
	complexPayload.addBadge(1);
	complexPayload.addSound("default");//铃声默认
	complexPayload.addCustomDictionary("type", "0");


	List<String> tokens = new ArrayList<String>();
	tokens.add("81d3788f2b3339990d9c3b1215a67a70975591304a20665e927668b282e6c782");//从苹果设备获得设备id
	List<PushedNotification> notifications = Push.payload(complexPayload, "证书路径", "密码", "正式或测试(true and false) ", tokens);
	
	//验证推送是否成功
	for (PushedNotification notification : notifications) {
		Log.info(Log.SYS, notification.toString());
		if (notification.isSuccessful()) {
			Log.info(Log.PUSH, "succ|" + notification.getDevice().getToken());
		} else {
			Log.info(Log.PUSH, "fail|" + notification.getDevice().getToken() + "|" + notification.getResponse().getMessage());
		}
	}


 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值