gpt4 book ai didi

java - 使用 SNS 有效负载长度的 Apple 推送通知消息

转载 作者:行者123 更新时间:2023-11-30 11:18:16 24 4
gpt4 key购买 nike

我正在使用 AWS SNS 将通知推送到苹果设备。但是,我面临着很多关于可以传递给 SNS 的消息长度的问题。例如。

如果我使用以下消息,它会被传送:

{
"default":"This is the default message",
"APNS":"{
\"aps\":{
\"badge\":9,
\"alert\":\"The ninth season of supernatural, an American paranormal drama television series created by Eric Kripke, premiered on October 8, 2013, concluded on May 20, 2014, and contained 23 episodes. On February 14, 201\",
\"sound\":\"default\"
}
}"
}

with alert's value(which is the actual message) : 208 characters
Total characters : 319 characters

但是如果我在消息中再添加 1 个字符(警报的值),它就不起作用。

同样,如果我使用以下 json,消息长度减少(减少 25 个字符)和 aps 中的 1 个额外参数,则工作长度如下:

{
"default":"This is the default message",
"APNS":"{
\"aps\":{
\"badge\":9,
\"alert\":\"The ninth season of supernatural, an American paranormal drama television series created by Eric Kripke, premiered on October 8, 2013, concluded on May 20, 2014, and contained 23 epis\",
\"sound\":\"default\"
},
\"sound\":\"newMessage.aif\"
}"
}

with alert's value(which is the actual message) : 183 characters
Total characters : 324 characters

但是,如果我在消息(警报值)中再添加 1 个字符,它就不起作用。

在发送消息之前,我似乎无法弄清楚我需要做多少修剪,以免失败。有人知道吗?

最佳答案

您的消息的有效载荷是:

{
"aps":{
"badge":9,
"alert":"The ninth season of supernatural, an American paranormal drama television series created by Eric Kripke, premiered on October 8, 2013, concluded on May 20, 2014, and contained 23 epis",
"sound":"default"
},
"sound":"newMessage.aif"
}

您在上面看到的所有字符的总长度,包括引号和方括号,应该 <= 256 字节(不仅仅是 alert 属性的内容)。您应该避免任何不属于警报消息的空格和换行符,因为它们也被计入 256 字节的限制。

请注意,您的第二个示例包含一个附加参数 "sound":"newMessage.aif"。这就是为什么您的警报剩余空间较少的原因。

顺便说一句,我不明白为什么要发送两次 sound 参数。这是一个错误吗?它应该只出现在 aps 字典中。

相关引自APNS guide :

Each push notification includes a payload. The payload contains information about how the system should alert the user as well as any custom data you provide. The maximum size allowed for a notification payload is 256 bytes; Apple Push Notification Service refuses any notification that exceeds this limit.

The examples are formatted with whitespace and line breaks for readability. In practice, omit whitespace and line breaks to reduce the size of the payload, improving network performance.

关于java - 使用 SNS 有效负载长度的 Apple 推送通知消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23931469/

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