我使用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
但是,如果我在消息中再添加一个字符(警报的值),它就不能工作。
同样,如果我使用以下的json,其消息长度(减少25个字符)和沿aps
增加一个参数,则工作长度如下:
{
"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
但是,如果我在消息中再添加一个字符(警报的值),它就不能工作。
在发送信息之前,我似乎无法计算出我需要做的修剪量,这样就不会失败。有人知道吗?
发布于 2014-05-29 14:33:12
您的邮件的有效负载是:
{
"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指南的相关引文:
每个推送通知都包含一个有效载荷。有效载荷包含有关系统应如何通知用户以及您提供的任何自定义数据的信息。允许通知有效负载的最大大小为256字节;Apple Push notification拒绝任何超过此限制的通知。 为了提高可读性,用空格和换行符对示例进行格式化。在实践中,省略空格和换行以减少有效负载的大小,从而提高网络性能。
https://stackoverflow.com/questions/23931469
复制相似问题