Google App Engine APNS

天涯浪子 提交于 2019-12-09 04:50:31

问题


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.

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.

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

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?


回答1:


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")

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.

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);



回答2:


AppEngine now supports Sockets so you should be able to use a slightly modified version of javapns now. I have successfully got PyAPNs working on AppEngine (python) which uses the new Socket functionality in 1.7.7.

If you are interested in seeing my python AppEngine project which does APNS, let me know and I will edit my answer with a link to it. Every time I post a link to it here, a moderator deletes my answer for some reason




回答3:


Since you need it for chat, trying thinking of posting the push notifications internally from the client itself (while your server providing the push tokens of your friends). It can fit well to your chat propose.




回答4:


Appengine now supports sockets in 1.7.7 so you can use APNS. The java runtime can use the java-apns lib with a minor modification. Here is a blogpost on the modifications needed.




回答5:


a very good news indeed .... official support now available no more in beta

http://googlecloudplatform.blogspot.in/2013/07/google-app-engine-takes-pain-out-of-sending-ios-push-notifications.html




回答6:


Google officially supports iOs push notification. You can take a look at this sample code: ios-push-notification-sample-backend-java and Google's post: Google app engine takes pain out of sending ios push notifications




回答7:


There is a thread discussing this here, and you can sign up for the sockets beta here.

I've no idea if that will let you do what you want to do, but the people on the latter thread seem to think it will.




回答8:


You may check out java-apns-gae.

It's an open-source Java APNS library that was specifically designed to work (and be used) on Google App Engine.



来源:https://stackoverflow.com/questions/13154987/google-app-engine-apns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!