Google App Engine APNS [英] Google App Engine APNS

查看:42
本文介绍了Google App Engine APNS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Java 中的 Google App Engine 和 JDO 为 iOS 应用程序开发服务器端,我刚刚意识到 GAE 不支持 Apple 推送通知服务,我非常沮丧.

Im developing the server side for an iOS app with Google App Engine and JDO in Java, and I just realized that GAE dont support Apple Push Notification Service, and I`m very frustrated.

我见过很多解决方案,例如 Urban Airship、xtify 等;但如果我拥有大量用户,那就太贵了.

I have been seen quite of solutions like Urban Airship, xtify, etc; but It`s too expensive if I reach to have an important amount of users.

另外,我一直在研究 Javapns 和类似的东西,但 GAE 也不支持 BouncyCastle.

Besides, I have been investigating about Javapns and similars, but GAE don`t support BouncyCastle either.

我想知道在我的 GAE 服务器中是否有免费或低成本的支持 APNS 的解决方案,因为我无法每月支付 200 美元.如果我的问题没有解决方案,是否可以构建另一台服务器,仅用于使用 javapns 执行 Apple 推送通知,并让我的 GAE 与之对话?

I want to know if there is a free or low cost solution for support APNS in my GAE server, because I can`t pay 200 $ per month. If there is not solution for my problem, would it been possible to build another server only for doing the Apple push notication with javapns, and that my GAE talks with it?

推荐答案

我使用第三方库 notnoop/java-apns.这个用起来很简单.您可能遇到的唯一问题是GAE 上的线程限制,如下面的 java 异常:

I use the 3rd-party library notnoop/java-apns. It is easy to use. The only problem you could meet is the thread limitation on the GAE like below java exception:

java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "modifyThreadGroup")

该问题在 1.0.0.Beta3 版本中得到解决 在 maven 中心.此拉取请求 #162 中解释了详细的解决方案.

The issue is solved in the version 1.0.0.Beta3 in the maven central. The detail solution is explained in this pull request #162.

所以,准备和发送推送通知到APNs的示例代码片段如下,解决线程限制的关键是方法withErrorDetectionThreadFactory如下

So, the example code snippet to prepare and send push notification to APNs is like below, the key to solve the thread limitation is the method withErrorDetectionThreadFactory as below

// Prepare ApnsService
ClassPathResource certificate = new ClassPathResource("aps_production.p12");

ApnsService service = null;
try {
    service = APNS.newService()
      .withErrorDetectionThreadFactory(ThreadManager.currentRequestThreadFactory()) // use GAE currentRequestThreadFactory
      .withCert(certificate.getInputStream(), certificatePassword)
      .withProductionDestination()
      .build();
} catch (InvalidSSLConfig | IOException e) {
    logger.warn("Fail to initialize APNs service");
}

// Send notification
String apnsPayload = APNS.newPayload()
    .alertBody("test alert")
    .badge(1)
    .sound("default")
    .customField("type", "general")
    .build();

service.push(<your device id>, apnsPayload);

这篇关于Google App Engine APNS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆