0
我正在使用notnoop/java-apns庫將消息從我的服務器推送到IOS設備。 推送正常,消息到達客戶端。notnoop/java-apns無法檢測到錯誤
我試圖檢測消息是否被推送到客戶端,但是 問題是我無法使用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");
}
}