谷歌App Engine的APNS [英] Google App Engine APNS

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

问题描述

林开发与谷歌App Engine和JDO Java中的iOS应用在服务器端,我只是意识到,GAE不支持苹果的推送通知服务,并且我真的很沮丧。

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.

我已经看到非常喜欢的城市飞艇,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苹果推商品通知的,而我用它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的中央。详细的解决方案是在这个pull请求#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.

所以,例如code段,以prepare和发送推送通知的APN就像下面,解决了线程的限制,关键是方法 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);

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

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