gpt4 book ai didi

java - 如何从 (Java) Date 对象中获取 Expiry 字段以发送到 Apple Push Notification Services?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:24:20 25 4
gpt4 key购买 nike

任何人都可以阐明增强型通知格式(用于发送到 Apple 推送通知服务)的到期字段中的 4 个字节是什么意思,就像使用 Java 与 APNS 服务器通信一样?比如说,如果我准备 Date 对象,我如何将它变成发送到 APNS 所需的 4 个字节?

最佳答案

APNS 文档指出:

Expiry—A fixed UNIX epoch date expressed in seconds (UTC) that identifies when the notification is no longer valid and can be discarded. The expiry value should be in network order (big endian). If the expiry value is positive, APNs tries to deliver the notification at least once. You can specify zero or a value less than zero to request that APNs not store the notification at all.

如果您有一个 Date 对象(我们称之为 date ),它包含您的消息应该过期的日期/时间,发送到 APNS 的过期的 4 个字节是 expiry 的值:

Calendar cal = Calendar.getInstance ();
cal.setTime (date);
int expiry = cal.getTimeInMillis () / 1000L;

或者你可以有一个相对的过期时间间隔。例如,如果您希望消息在发送到 APNS 服务器后 2 小时(7200 秒)过期,则 expiry 的值将是:

int expiry = (System.currentTimeMillis () / 1000L) + 7200;

关于java - 如何从 (Java) Date 对象中获取 Expiry 字段以发送到 Apple Push Notification Services?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12380482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com