IOS 基于APNS消息推送原理与实现(JAVA后台) 联系客服

发布时间 : 星期二 文章IOS 基于APNS消息推送原理与实现(JAVA后台)更新完毕开始阅读fd0235e231b765ce050814aa

}

3、在项目AppDelegate.m中加入消息接收处理代理方法。 //处理收到的消息推送

- (void)application:(UIApplication *)application

didReceiveRemoteNotification:(NSDictionary *)userInfo {

//在此处理接收到的消息。

NSLog(@\}

六、JAVA后台代码:

public static void main(String[] args) throws Exception { try {

//从客户端获取的deviceToken,在此为了测试简单,写固定的一个测试设备标识。

String deviceToken = \ System.out.println(\ //定义消息模式

PayLoad payLoad = new PayLoad(); payLoad.addAlert(\

payLoad.addBadge(1);//消息推送标记数,小红圈中显示的数字。 payLoad.addSound(\ //注册deviceToken

PushNotificationManager pushManager = PushNotificationManager.getInstance(); pushManager.addDevice(\ //连接APNS

String host = \ //String host = \ int port = 2195;

String certificatePath = \前面生成的用于JAVA后台连接APNS服务的*.p12文件位置 String certificatePassword = \文件密码。

pushManager.initializeConnection(host, port, certificatePath, certificatePassword, SSLConnectionHelper.KEYSTORE_TYPE_PKCS12); //发送推送

Device client = pushManager.getDevice(\

System.out.println(\推送消息: \ pushManager.sendNotification(client, payLoad); //停止连接APNS

pushManager.stopConnection(); //删除deviceToken

pushManager.removeDevice(\ System.out.println(\ }

catch (Exception ex)

{

ex.printStackTrace(); } } }

至此大功告成,测试通过。

以上在Iphone4,IPAD2设备测试通过,Iphone3g,3gs需要打PushDoctor(推送医生)补丁才能测试通过。