簡體   English   中英

notnoop / java-apns無法檢測到錯誤

[英]notnoop/java-apns can't detect error

我正在使用notnoop / java-apns庫將消息從服​​務器推送到IOS設備。 推送正常,消息到達客戶端。

我正在嘗試檢測是否將郵件推送到客戶端,但問題是我無法使用EnhancedApnsNotification並實現ApnsDelegate類來檢測推送郵件的錯誤/成功。

未調用messageSendFailed和messageSent

我的密碼

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

}

我認為代表只是沒有連接到該服務。 創建一個委托,然后使用構建器的withDelegate(..)方法進行連接。

public class MyApnsDelegate extends ApnsDelegateAdapter {


    Logger log = LoggerFactory.getLogger(MyApnsDelegate.class);

    @Override
    public void messageSent(ApnsNotification apnsNotification, boolean b)
    {
        log.info("MyApnsDelegate called!");
    }
}

然后,在設置APNS服務的代碼中,APNS.newService()返回一個ApnsServiceBuilder,可讓您設置委托:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM