获取在JavaPNS中卸载应用程序的设备的成功状态

时间:2013-01-04 07:35:47

标签: iphone apple-push-notifications

我正在测试设备已卸载该应用的情况。

当我尝试通过JavaPNS将通知推送到卸载应用程序的iPhone时,我获得了成功,但在设备中没有收到任何消息。

为什么即使设备上不再安装相关应用程序,JavaPNS也会返回成功? 我该如何解决这个问题?

        for (PushedNotification notification : notifications) {
            if (notification.isSuccessful()) {
                //success
            } else {
                iPhoneFailedPushed += 1;
                String deviceId = notification.getDevice() != null ? notification.getDevice().getDeviceId() : "";
                String exception = notification.getException() != null ? notification.getException().getMessage() : "";
                /* Add code here to remove invalidToken from database */
                if (notification.getResponse() != null)
                {
                    //show error code
                }
                else
                {
                    //show exception                
                }
                //log fail token
            }
        }

1 个答案:

答案 0 :(得分:1)

在这种情况下,您永远不会收到错误响应数据包,因为这是一个有效的设备令牌(卸载应用程序不会改变它)。检测应用程序已卸载的唯一方法是使用反馈服务。

来自APNS文件:

  

如果提供商尝试向其发送推送通知   应用程序,但该应用程序不再存在于该设备上   设备向Apple推送通知服务报告该事实。这个   当用户卸载应用程序时经常会发生这种情况。   如果设备报告应用程序的失败传递尝试,则为APN   需要一些方法来通知提供商,以便它可以避免   向该设备发送通知。这样做减少了不必要的   消息开销并提高整体系统性能。

     

为此,Apple推送通知服务包含反馈   APN持续更新的服务,每个应用程序列表   发生故障的设备。这些设备是   由以二进制格式编码的设备令牌识别。提供商应该   定期查询反馈服务以获取设备列表   代币用于其应用程序,每个代码都由其标识   话题。然后,在验证应用程序最近没有   在已识别的设备上重新注册,提供商应该停止   向这些设备发送通知。