简体   繁体   English

你如何设置javapns(iOS的推送通知)?

[英]How do you set up javapns (push notifications for iOS)?

I have had a look at the documentation / wiki for javapns. 我看过javapns的文档/ wiki。 http://code.google.com/p/javapns/ http://code.google.com/p/javapns/

Unfortunately, what should be obvious is anything but obvious to me. 不幸的是,显而易见的事情对我来说是显而易见的。

How do I set up a working push notification server? 如何设置工作推送通知服务器? As in, there's a .jar file, but I would appreciate more info than that. 就像在,有一个.jar文件,但我会感谢更多的信息。 Do I need to run this in Tomcat? 我需要在Tomcat中运行吗? Is there a working example?' 有一个有效的例子吗?

Thanks. 谢谢。

I have used Java APNS in the past. 我过去使用过Java APNS It has a BSD License and did a perfect job and was quite easy to use once the certificates were set up. 它具有BSD许可证并且完成了一项完美的工作,并且在设置证书后非常容易使用。 All in all it is not a dead-simple task to set up Push notifications, but I usually got usable debug output if there was anything not quite working yet. 总而言之,设置推送通知并不是一项简单的任务,但如果还有任何工作尚未完成,我通常会获得可用的调试输出。

A good thing about this solution is that you can run it stand alone java -jar MyAPNSPusher and trigger it with some cron job or include the logic in some .war file. 这个解决方案的一个好处是你可以独立运行java -jar MyAPNSPusher并用一些cron作业触发它或在某些.war文件中包含逻辑。 I also found that the library was quite lightweight and I guess you can also find it in a maven repo. 我还发现该库非常轻巧,我想你也可以在maven回购中找到它。

Example from the Readme.markdown Readme.markdown中的示例

To send a notification, you can do it in two steps: 要发送通知,您可以分两步完成:

  1. Setup the connection 设置连接

     ApnsService service = APNS.newService() .withCert("/path/to/certificate.p12", "MyCertPassword") .withSandboxDestination() .build(); 
  2. Create and send the message 创建并发送消息

     String payload = APNS.newPayload().alertBody("Can't be simpler than this!").build(); String token = "fedfbcfb...."; service.push(token, payload); 

[...]

Alternatives 备择方案

If hosting your own server solution is too cumbersome then you can fallback to a thirdparty service which might often be a good thing because hosting a server with such a service running on it is probably often underestimated. 如果托管您自己的服务器解决方案过于繁琐,那么您可以回退到第三方服务,这可能通常是一件好事,因为托管运行此类服务的服务器可能经常被低估。 With those services you usually pay a tiny amount (fractions of a cent) for a push message. 通过这些服务,您通常会为推送消息支付少量(几分之一)。 Two that I have come across are 我遇到的两个是

JavaPNS is a java library used within your project. JavaPNS是项目中使用的Java库。 It can only be used to connect to the Apple Push Notification Servers, using the certificates that you create on the Apple Developer Tools Website. 它只能用于使用您在Apple Developer Tools网站上创建的证书连接到Apple推送通知服务器。

So, if I'm reading your question properly, this is not a stand-alone program and probably not what you want. 所以,如果我正确地阅读你的问题,这不是一个独立的程序,可能不是你想要的。

If you are trying to send push notifications to Apple iOS devices, then this IS what you want, but you need to write the rest of your application first, then add this library to it. 如果您尝试向Apple iOS设备发送推送通知,那么这就是您想要的,但您需要先编写应用程序的其余部分,然后将此库添加到其中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM