ResponsePacket theErrorResponse = pushingNotification.getResponse();我正在使用javapns2.2并试图从apple的增强通知格式中捕获错误响应数据包。当我发送推送通知(例如,使用无效令牌)时代码
Exception theProblem = pushedNotification.getException();
theProblem.printStackTrace();
向控制台输出一些错误,但
ResponsePacket theErrorResponse = pushedNotification.getResponse();
if (theErrorResponse != null && theErrorResponse.isErrorResponsePacket()) {
System.out.println(theErrorResponse.getMessage());
System.out.println(theErrorResponse.getStatus());
}
始终返回 null。如何使用getResponse()获取状态代码?
以下是我的代码的一部分:
List<PushedNotification> notifications = Push.payload(payload, keystore, password, production, devices);
for (PushedNotification pushedNotification : notifications) {
if(pushedNotification.isSuccessful())
{
System.out.println(pushedNotification.getDevice().getToken());
}
else
{
System.out.println(pushedNotification.getDevice().getToken());
Exception theProblem = pushedNotification.getException();
theProblem.printStackTrace();
ResponsePacket theErrorResponse = pushedNotification.getResponse();
if (theErrorResponse != null && theErrorResponse.isErrorResponsePacket()) {
System.out.println(theErrorResponse.getMessage());
System.out.println(theErrorResponse.getStatus());
}
}
}
感谢您的帮助
答案 0 :(得分:1)
我明白了。
getResponse()返回null,因为异常机制阻止对APN的调用更有效。真正的错误包含在异常机制中。
在此链接中,所有内容均为超级解释: http://code.google.com/p/javapns/issues/detail?id=79&can=1