JavaPNS 错误处理 - 文档中的矛盾? [英] JavaPNS error handling - contradiction in the documentation?

查看:20
本文介绍了JavaPNS 错误处理 - 文档中的矛盾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 JavaPNS 文档中,我看到了:

In the JavaPNS docs, I see this:

要确定推送是否成功发送到 Apple 并且 Apple 没有返回任何错误响应数据包,只需调用 pushNotification.isSuccessful() 方法.如果出现以下任何一种情况,通知可能不会成功:

To find out if a push was successfully sent to Apple and that Apple did not return any error-response packet, simply invoke the pushedNotification.isSuccessful() method. A notification might not be successful if any of these conditions occur:

  • 图书馆拒绝了您提供的令牌,因为明显违反了规范(例如:令牌不是 64 字节长等)
  • 库拒绝了您提供的有效负载,因为明显违反了规范(例如:有效负载太大等)
  • 发生连接错误,库无法与 Apple 服务器通信
  • 您的证书或密钥库出错(例如:密码错误、密钥库格式无效等)
  • 从 Apple 服务器收到一个有效的错误响应数据包

以及许多其他可能的错误...

但是提供的代码片段确实如此

But the code snippet provided then does

for (PushedNotification notification : notifications) {
    if (notification.isSuccessful()) {
        /* Apple accepted the notification and should deliver it */  
        System.out.println("Push notification sent successfully to: " + notification.getDevice().getToken());
    /* Still need to query the Feedback Service regularly */  
    } else {
        String invalidToken = notification.getDevice().getToken();
        /* Add code here to remove invalidToken from your database */  

        /* Find out more about what the problem was */  
        Exception theProblem = notification.getException();
        theProblem.printStackTrace();

        /* If the problem was an error-response packet returned by Apple, get it */  
        ResponsePacket theErrorResponse = notification.getResponse();
        if (theErrorResponse != null) {
            System.out.println(theErrorResponse.getMessage());
        }
     }
 }

这似乎暗示 isSuccess() == false 意味着不可恢复的错误,并且设备令牌无效.

Which seems to imply that isSuccess() == false means an unrecoverable error, and that the device token is not valid.

然而,可能的原因列表确实表明 isSUccess() 可能是错误的,因为返回了一个合法的错误数据包.我不知道,但我想如果 Apple 由于运营商问题未能发送通知,则可能会退回,例如,这意味着令牌不一定无效.

However, the list of possible reasons did say that isSUccess() might be false due to a legitimate error packet being returned. I don't know, but I imagine one might be returned if Apple failed to send the notification due carrier issues, for example, which means the token is not necessarily invalid.

这是正确的阅读方式,那么,isSuccess() == false 是发送消息时不可恢复的错误,但不是需要异常的错误,例如密钥库失败或无法连接到服务器全部?

Is the correct way to read this, then, that isSuccess() == false is an unrecoverable error when sending a message, but not one that requires an exception, like a keystore fail or an inability to connect to the servers at all?

换句话说 - id isSuccessful() == false,我真的应该按照建议从我的数据库中删除设备令牌吗?片段说是的,但在我看来,文档似乎另有建议...

In other words - id isSuccessful() == false, should I really delete the device token from my DB as suggested? The snippet says yes, but the documentation seems to me to suggest otherwise...

链接:http://code.google.com/p/javapns/wiki/管理推送错误

提前感谢所有敢于提出这个冗长而漫无目的问题的人.

Thanks in advance to anyone who has braved this long, rambling question.

-- 浮潜

推荐答案

文档说你是对的.从技术上讲,这意味着推送失败,但不是因为异常而失败.它可能因为合法的失败而失败.(我将连接成功定义为合法失败,消息没有明显缺陷,但服务器拒绝接受.)关键行如下:

The documentation says that you are correct. Technically it means the push failed, but not that it failed because of an exception. It could have failed because of a legitimate failure. (I define legitimate failure as we successfully connected, there were no obvious defects with the message, but the server declined to accept it.) The key line is the following:

IE 要查看推送是否成功发送到 Apple 并且 Apple 没有返回任何错误响应数据包,只需调用 pushNotification.isSuccessful() 方法即可.

不过,您的整个问题似乎很迂回.简单来说,你的推送失败了.异常和失败之间的区别真的很重要吗?无论哪种方式,它都无法恢复,您需要检查日志以确切了解发生了什么.

Your whole question seems pretty roundabout though. In a simple sense, your push failed. Does the distinction between an exception and a failure really matter? Either way its unrecoverable and you need to check the logs to see exactly what happened.

这篇关于JavaPNS 错误处理 - 文档中的矛盾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆