NOTNOP/java APN可以';无法检测错误

NOTNOP/java APN可以';无法检测错误,java,push,Java,Push,我正在使用notnoop/javaapns库将消息从服务器推送到IOS设备。 推送工作正常,消息到达客户端 我试图检测消息是否被推送到客户端,但是 问题是,我无法使用EnhancedApnsNotification检测推送消息的错误/成功,并实现ApnsDelegate类 messageSendFailed&未调用MessageSend 我的代码 public class PushTest implements ApnsDelegate { private static pushtest in

我正在使用notnoop/javaapns库将消息从服务器推送到IOS设备。 推送工作正常,消息到达客户端

我试图检测消息是否被推送到客户端,但是 问题是,我无法使用EnhancedApnsNotification检测推送消息的错误/成功,并实现ApnsDelegate类

messageSendFailed&未调用MessageSend

我的代码

public class PushTest  implements ApnsDelegate {
private static pushtest instance = null;

private static ApnsService service;
private static int counter= 0;

private pushtest() {
}

static public PushTest instance() {
    if (instance == null) {
        instance = new pushtest();
        try {
            service =  APNS.newService()
                    .withCert("certPath", "password")
                    .withSandboxDestination()
                    .build();       
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return instance;
}

public void send(String token) {
    LinkedHashMap<String, Boolean> result = new LinkedHashMap<String, Boolean>();
    // build payload
     int now =  (int)(new Date().getTime()/1000);

    try {
         String payload = APNS.newPayload()
                .badge(3)
                .alertBody("test")
                .build();
     EnhancedApnsNotification notification = new EnhancedApnsNotification(counter++,
         now + 60 * 60 /* Expire in one hour */,
         token /* Device Token */,
         payload);
     service.push(notification);    
    } catch (Exception e1) {
        System.out.println("IosPush :" + e1.getMessage());
    }
}
@Override
public void connectionClosed(DeliveryError arg0, int arg1) {
    System.out.println("connectionClosed");     
}
@Override
public void messageSendFailed(ApnsNotification arg0, Throwable arg1) {
    System.out.println("messageSendFailed");
}
@Override
public void messageSent(ApnsNotification arg0) {
    System.out.println("messageSent");
}
公共类PushTest实现ApnsDelegate{
私有静态pushtest实例=null;
专用静态ApnsService服务;
专用静态整数计数器=0;
私人pushtest(){
}
静态公共PushTest实例(){
if(实例==null){
实例=新的pushtest();
试一试{
service=APNS.newService()
.withCert(“certPath”、“密码”)
.withSandboxDestination()
.build();
}捕获(例外e){
e、 printStackTrace();
}
}
返回实例;
}
公共无效发送(字符串令牌){
LinkedHashMap结果=新建LinkedHashMap();
//构建有效载荷
int now=(int)(new Date().getTime()/1000);
试一试{
字符串有效负载=APNS.newPayload()
.徽章(3)
.alertBody(“测试”)
.build();
EnhancedApnsNotification通知=新的EnhancedApnsNotification(计数器+++,
现在+60*60/*一小时后过期*/,,
令牌/*设备令牌*/,,
有效载荷);
服务推送(通知);
}捕获(异常e1){
System.out.println(“IosPush:+e1.getMessage());
}
}
@凌驾
公共无效连接已关闭(DeliveryError arg0,int arg1){
System.out.println(“连接关闭”);
}
@凌驾
public void messageSendFailed(通知arg0,可丢弃arg1){
System.out.println(“messageSendFailed”);
}
@凌驾
已发送公共无效消息(通知arg0){
System.out.println(“messageSent”);
}

}

我认为该代表没有连接到该服务。创建一个委托,然后使用生成器的withDelegate(..)方法将其连接起来

然后,在设置APNS服务的代码中,APNS.newService()返回一个ApnsServiceBuilder,可用于设置委托:

service =  APNS.newService()
               .withCert("certPath", "password")
               .withSandboxDestination()
               .withDelegate(new MyApnsDelegate())
               .build();
service =  APNS.newService()
               .withCert("certPath", "password")
               .withSandboxDestination()
               .withDelegate(new MyApnsDelegate())
               .build();