Java通过APNS推送消息:dbay-apns-for-java

推荐一下。

https://github.com/RamosLi/dbay-apns-for-java

 

 

Introduction

I’m developing an application and need to send notifications to the iOS devices. In the past year, I had used Java-APNS which I think is much better than other libs, such as JavaPNS and so on. But there are still some problem. For example, sometime an exception was thrown: java.lang.StackOverflowError. And the device couldn’t receive notifications after a period time. Then I used JSTACK and JMAP to find what happened, that’s DEADLOCK, I found, which caused Java-APNS didn’t work any more. I had to restart the service to recover it. That’s terrible. So I decide to develop a new Java client for APNS. Then dbay-apns4j comes. It’s best, I think.

Features

  • High performance and easy to use
  • Gets started quickly with demos
  • Supports connection pooling
  • 中英双语注释,英语小白阅读起来也没问题
  • Supports resend notifications after error
  • Creates new socket automatically when idle
  • Supports the Feedback Service
  • Supports the sandbox and production services
  • Detailed and useful log

Demos

You can find demo in the package. In this file: com.dbay.apns4j.demo.Apns4jDemo.java

Sample code

  1. Create an ApnsService
  2. private static IApnsService apnsService;
  3. if (apnsService == null) {
  4. ApnsConfig config = new ApnsConfig();
  5. InputStream is = Apns4jDemo.class.getClassLoader().getResourceAsStream(“Certificate.p12”);
  6. config.setKeyStore(is);
  7. config.setDevEnv(false);
  8. config.setPassword(“123123”);
  9. config.setPoolSize(5);
  10. apnsService = ApnsServiceImpl.createInstance(config);
  11. }
  12. Send notification
  13. String token = “94c4764e4545f41a7b2052692c8a9b41f9c5c925876e11fec5721d9074ee5e5a”;
  14. Payload payload = new Payload();
  15. payload.setAlert(“Hello, how are you?”);
  16. //payload.setAlertBody(“alert body”);
  17. //payload.setAlertLocKey(“use emotion ok”);
  18. //payload.setAlertLocArgs(new String[]{“3”});
  19. //payload.setAlertActionLocKey(“lbg_loading_text_0”);
  20. payload.setBadge(1);
  21. payload.setSound(“msg.mp3”);
  22. //payload.addParam(“uid”, 123456);
  23. //payload.addParam(“type”, 12);
  24. //payload.setContentAvailable(1);
  25.  
  26. service.sendNotification(token, payload);

Contact

If you are using dbay-apns4j, let me know and keep in touch, thx. You can send an email to me:lzhc2004@163.com

Tips

2014-09-22ios8更新后,如果没有设置声音(Payload.setSound()),那么手机收到推送很可能不响。
此时需要更新dbay-apns4j包,或者自己设置下声音。eg: Payload.setSound(“xx”)。注意不能设为空串,否则不响,设为任意串均可。