java - 如何使用 javapns 从苹果的增强型通知格式中获取错误响应数据包

标签 java ios apple-push-notifications

ResponsePacket theErrorResponse = PushNotification.getResponse();我正在使用javapns2.2并尝试从苹果的增强型通知格式捕获错误响应数据包。当我发送推送通知(例如使用无效 token )时,代码

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

            }
        }

感谢您的帮助

最佳答案

我明白了。

getResponse() 返回 null,因为异常机制阻止了对 APN 的调用更加高效。真正的错误被打包在异常机制中。

一切都在这个链接中得到了 super 解释: http://code.google.com/p/javapns/issues/detail?id=79&can=1

关于java - 如何使用 javapns 从苹果的增强型通知格式中获取错误响应数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10637212/

相关文章:

java - 在我的 JSP 中引用 Java 的最佳实践

java - 次要垃圾收集时间过长

ios - 减少 JPEG 和 PNG 文件大小的最佳程序

具有多个目标的 iOS 通知服务扩展从不调用扩展方法

ios - APNs 证书更改后,FCM 不发送推送通知

java - 从流中安全解析字节数组的最佳分隔符

java - 如何在 Android API O 中设置音频焦点 ChangeListener?

ios - SwiftUI NavigationLink isActive 绑定(bind)未更新/工作

iphone - isAvailableForServiceType 总是返回 true?

ios - 如何使用FCM向iOS发送通知?