简体   繁体   English

苹果推送通知消息,使用SNS有效载荷长度

[英]Apple Push Notifiction message using SNS Payload length

I am using AWS SNS for pushing notification to apple devices. 我正在使用AWS SNS将通知推送到Apple设备。 However, I am facing a lot of issue regarding the length of the message that can be passed to the SNS. 但是,关于可以传递到SNS的消息长度,我面临很多问题。 Eg. 例如。

If i'm using the following message, it gets delivered: 如果我使用以下消息,它将被发送:

{
    "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

But if I add 1 more character in the message(alert's value), it doesn't work. 但是,如果我在消息中再添加1个字符(警报值),它将无法正常工作。

Again, If I use the following json with reduced message length(by 25 characters) and 1 extra parameter along aps the working lengths are as follows: 同样,如果我使用以下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

However, if I add 1 more character to message(alert's value), it doesn't work. 但是,如果我再添加1个字符到消息(警报值),它将不起作用。

I can't seem to figure out the amount of trimming I need to do, before sending the messages, so that it doesn't fail. 我似乎无法弄清楚在发送消息之前我需要做的修剪量,以确保它不会失败。 Any body got any idea? 有人知道吗?

The payload of your message is : 您的消息的有效负载为:

{
     "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"
}

The total length of all the characters you see above, including the quotes and the brackets, should be <= 256 bytes (not just the content of the alert property). 您在上面看到的所有字符的总长度(包括引号和括号)应小于等于256个字节(而不仅仅是alert属性的内容)。 You should avoid any spaces and new-lines that are not part of the alert message, because those are also counted toward the 256 bytes limit. 您应该避免任何不属于警报消息的空格和换行符,因为这些空格和换行符也计入256个字节的限制。

Note that your second example contains an additional parameter "sound":"newMessage.aif" . 请注意,第二个示例包含一个附加参数"sound":"newMessage.aif" That's why you have less remaining space for your alert. 这就是为什么您的警报剩余空间更少的原因。

BTW, I don't understand why you send the sound parameter twice. 顺便说一句,我不明白为什么您两次发送sound参数。 Is it a mistake? 错了吗 It should only appear inside the aps dictionary. 它仅应出现在aps词典中。

Relevant quotes from the APNS guide : APNS指南中的相关引用:

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; 通知有效负载允许的最大大小为256个字节; Apple Push Notification Service refuses any notification that exceeds this limit. Apple Push Notification Service拒绝任何超过此限制的通知。

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. 实际上,请省略空格和换行符以减小有效负载的大小,从而改善网络性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM