今天很顺利的弄了一个java push iphone的小程序,拿出来和大家分享一下吧。
前期准备工作:
1. p12文件
2. 在生成p12文件时所需要的密码
3. 测试机器的tonken码
4. 需要以下类库,bcprov-jdk16-145-1.jar
commons-io-2.0.1.jar
commons-lang-2.5.jar
javapns-jdk16-163.jar
log4j-1.2.16.jar
准备工作已经做好,下面就是主要的java代码部分了:
try {
String deviceToken = "98ea484fa 4fe8871a eb8e558d 0d443ee4 a89fb3bd 27d07c13 9e5e36a0 d2b726ad";//iphone手机获取的token
PayLoad payLoad = new PayLoad();
payLoad.addAlert("我的push测试");//push的内容
payLoad.addBadge(1);//图标小红圈的数值
payLoad.addSound("default");//铃音
PushNotificationManager pushManager = PushNotificationManager.getInstance();
pushManager.addDevice("iPhone",deviceToken);
//Connect to APNs
//************************************************
//测试的服务器地址:gateway.sandbox.push.apple.com /端口2195
// 产品推送服务器地址:gateway.push.apple.com / 2195
//***************************************************/
String host= "gateway.sandbox.push.apple.com";
int port = 2195;
String certificatePath= "F:\\iphone.p12";//导出的证书
String certificatePassword= "iphone";//此处注意导出的证书密码不能为空因为空密码会报错
pushManager.initializeConnection(host, port,
certificatePath, certificatePassword,
SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
//Send Push
Device client = pushManager.getDevice("iPhone");
pushManager.sendNotification(client, payLoad);
pushManager.stopConnection();
pushManager.removeDevice("iPhone");
System.out.println("OK");
}
catch (Exception e) {
e.printStackTrace();
}
如果测试成功会在控制台打印出"OK"
有一个做好的例子,我也拿出来了,请查看附件。
分享到:
相关推荐
iPhone实现push功能的参考源码,pushMe作为服务器端,pushTest作为客户端。
那个 iphone push notifacation 的介绍的源码文件 其中包括克服段的pushClient 和provider的 pushBabyMe
使用java代码向iphone发送推送消息,配合使用代码Demo https://blog.csdn.net/wxx_csdn/article/details/90715448
iPhone iOS Push Test.
Provider是指某个iPhone软件的Push服务器。 APNS 是Apple Push Notification Service(Apple Push服务器)的缩写,下文统一使用该缩写。 因 此,整个过程可以分为三个阶段,下面用大家常用的聊天客户端BeejiveIM来...
关于iphone中push notification得实现参考文档
这是一个完整的iphone推送机制的.net平台实现
push notificaiton 苹果的消息推送功能
push独立证书,完美修复后台推送问题!iphone推送证书,iphone推送修复!定义.pdf
Using new Push Notifications to send alerts, whether your app is running or not Playing audio and video with the MediaKit Working with the Address Book, Core Location, and Sensors Connecting to...
Wireless E-Mail Efficiency Assessment, RIM BlackBerry and Microsoft Direct Push (Including iPhone) (2009) 36p R20090611J
Apress 2010, Everyone is developing iPhone applications, and it’s ...Chapter 10: Implementing Push Notifications at eBuddy amazon link:http://www.amazon.com/exec/obidos/ASIN/1430229225/buythisbooks-20
Work with the Apple Push Notification Service Use the Map Kit API to create apps with embedded maps Record audio, play video, and access the iPod Library Set up your developer certificates and code...
这是一个推送工具类,作为移动推动的后台服务...它: 1. 支持Android推送,使用百度云推送。...2. 支持IOS(Apple/iPhone)推送,使用APNS-Sharp(参考代码:https://github.com/Redth/APNS-Sharp) 百度的那块改写自APNS.
Work with the Apple Push Notification Service Use the Map Kit API to create apps with embedded maps Record audio, play video, and access the iPod Library Set up your developer certificates and code ...
Also included is coverage of the latest iPhone- and iPad-specific enterprise technologies (such as push notification and calendaring tools) as well as internal iPhone and iPad applications and web-...
然后随后将服务器的信息接收并且保存在APNS当中,APNS从其中注册的列表中查找该设备(设备可以为iPhone、iPad、iTouch)并将信息发送到该设备;最后,设备接收到数据信息给相应的APP,并按照设定弹出Push信息。
很有用的东西生生世世生生世世生生世世事实上生生世世生生世世是说