[ThirdParty]notnoop / java-apns

notnoop/java-apns github:https://github.com/notnoop/java-apns

简介

java-apns是服务于APNS服务的java客户端,该库目的是提供一套面对苹果服务器的高扩展性、简单、模块化的接口。

这些接口只需要很少的代码去完成大多数的cases,同时你还可以用永自己的网络链接库或者json库重新配置java-apns库。

Links: Installation

  • Javadocs
  • Changelog

细节:

  • 简单易用,高性能的APNS API
  • 支持Apple反馈服务
  • 支持增强的Apple Push Notification
  • 支持MDM和NewStand Notification
  • 方便读取Apple certificates
  • 方便扩展&复用
  • 容易集成在框架中
  • 自定义push负载
  • 支持pooling的链接
  • 遇错重连

Sample Code

To send a notification, you can do it in two steps:

  1. 建立连接

    ApnsService service =
        APNS.newService()
        .withCert("/path/to/certificate.p12", "MyCertPassword")
        .withSandboxDestination()
        .build();

     

  2. 创建&发送消息

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

     

  3. 通过反馈服务获取不活动的设备列表

    Map<String, Date> inactiveDevices = service.getInactiveDevices();
    for (String deviceToken : inactiveDevices.keySet()) {
        Date inactiveAsOf = inactiveDevices.get(deviceToken);
        ...
    }

     

     

自定义发送内容

你可以发送自定义的消息,支持自定义的字段

String payload = APNS.newPayload()
            .badge(3)
            .customField("secret", "what do you think?");
            .localizedKey("GAME_PLAY_REQUEST_FORMAT")
            .localizedArguments("Jenna", "Frank")
            .actionKey("Play").build();

service.push(token, payload);

 

增强的Notification Push Format

 String payload = APNS.newPayload()
            .badge(3)
            .customField("secret", "what do you think?");
            .localizedKey("GAME_PLAY_REQUEST_FORMAT")
            .localizedArguments("Jenna", "Frank")
            .actionKey("Play").build();

 EnhancedApnsNotification notification = new EnhancedApnsNotification(EnhancedApnsNotification.INCREMENT_ID() /* Next ID */,
     new Date().getTime() + 60 * 60 /* Expire in one hour */,
     token /* Device Token */,
     payload);

 service.push(notification);

 

 
 
 

你可能感兴趣的:([ThirdParty]notnoop / java-apns)