iPhone 推送通知字符数限制
我是 IOS 推送通知的新手。我一直在阅读有关它们的信息,但似乎无法在任何地方找到此信息。我读到推送通知的大小限制是 256 字节。此大小限制是否包括必须发送的设备令牌以及有关通知的其他开销信息等内容。如果是这样,我的内容可用的实际大小是多少。
他们使用什么格式来解释我发送的文本?转换 1 个字符 = 1 个字节还是更多。我真的想知道我可以在推送通知中发送多少个字符。
感谢您在了解推送通知有效负载的限制方面提供的任何帮助。
I'm brand new to IOS push notifications. I have been reading about them and can't seem to find this information anywhere. I have read that the size limit on a push notification is 256 Bytes. Does this size limit include things such as the device token that have to be sent and other overhead information about the notification. If so what is the actual size I have avaliable for my content.
Also what format are they using to interpret the text that I send? Is the conversion 1 character = 1 byte or is it more than that. Really I want to know how many characters can I send in a push notifications.
Thanks for any help in understanding the limitations of push notification payloads.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
-
本地和推送通知编程指南
所以,回答你的问题,
是的,此大小限制包括设备令牌和其他开销信息。
如果您在通知中仅使用拉丁字母,则情况确实如此。
-
Local and Push Notifications Programming Guide
So, answering your question,
Yes, this size limit includes device token and other overhead information.
This is true if you're using only Latin letters in your notification.
上面的内容都相当不清楚,因为“包含”可能意味着“它已经包含”或“您必须包含它”。需要明确的是,设备 ID 是“元数据”,不是有效负载的一部分,并且不会超出您的 256 个字符预算。不过,另一个 APS 开销(标准有效负载字典)是。
来源:以上文档加实验验证。
The above is all fairly unclear, because 'include' can mean "it is already included" or "you must include it". To be very clear, the device ID is 'metadata', not part of the payload, and does not come out of your 256 character budget. The other APS overhead (standard payload dictionary), though, is.
Source: the above documentation plus experimentation to verify.
我在生产环境的APNS测试中,最多可以成功发送33个汉字和2个13字节的自定义属性。
如果保存为文件,上面的有效负载长度为 158 字节,不包括空格字符。
每个汉字被算作 3 个字节(我通过删除所有汉字来查看大小变化来确认这一点)。
正如官方文档提到的,256 字节的限制不包括设备令牌,但我相信还有其他字符 APNS 也被计算在内,例如“声音”和“内容可用”,即使您没有明确使用。
因此请注意不要“太长”,尤其是在使用自定义负载时。
请注意,APNS 开发环境不限制有效负载长度。您在使用开发环境时测试通过,但在产品中可能会失败。不要认为这是确定的。
In my APNS test in the production environment, up to 33 Chinese characters and 2 custom properties of 13 bytes could be sent successfully.
The above payload length was 158 bytes if saved as file, not counting the space characters.
Each Chinese character was counted as 3 bytes (I confirmed that by removing all of them to see the size change).
As official document mentioned, the 256-bytes limitation does not include the device token , but I believe there are other characters APNS are counted in, such as 'sound' and 'content-available' even if you do not use explicitly.
So be careful not to be 'too long', especially when using custom payloads.
Be aware that APNS development environment does not limit the payload length. Your test pass while using development environment, but may fail in product. Do not take it as certain.
更新 2023
对于像我这样最近在 2023 年遇到这个问题的人,Apple 文档有关
Update 2023
For those, like me, who have come to this question recently, in 2023, Apple documentation about Generating a remote notification says: