ios iPhone 推送通知字符限制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9182572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iPhone Push Notification Character Limit
提问by jcmitch
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.
我是 IOS 推送通知的新手。我一直在阅读有关它们的信息,但似乎在任何地方都找不到这些信息。我已经读到推送通知的大小限制是 256 字节。此大小限制是否包括诸如必须发送的设备令牌和有关通知的其他开销信息之类的内容。如果是这样,我的内容可用的实际大小是多少。
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.
还有他们使用什么格式来解释我发送的文本?转换是 1 个字符 = 1 个字节还是更多。我真的想知道我可以在推送通知中发送多少个字符。
Thanks for any help in understanding the limitations of push notification payloads.
感谢您在理解推送通知负载限制方面的任何帮助。
回答by Andrey Zverev
Each push notification carries with it a payload. The payload specifies how users are to be alerted to the data waiting to be downloaded to the client application. The maximum size allowed for a notification payload is 256 bytes; Apple Push Notification Service refuses any notification that exceeds this limit.
For each notification, providers must compose a JSON dictionary object that strictly adheres to RFC 4627. This dictionary must contain another dictionary identified by the key aps. The aps dictionary contains one or more properties that specify the following actions:
- An alert message to display to the user
- A number to badge the application icon with
- A sound to play
每个推送通知都带有一个负载。负载指定如何提醒用户等待下载到客户端应用程序的数据。通知负载允许的最大大小为 256 字节;Apple 推送通知服务拒绝任何超过此限制的通知。
对于每个通知,提供者必须编写一个严格遵守 RFC 4627 的 JSON 字典对象。该字典必须包含另一个由密钥 aps 标识的字典。aps 字典包含一个或多个指定以下操作的属性:
- 显示给用户的警报消息
- 用于标记应用程序图标的数字
- 播放的声音
- Local and Push Notifications Programming Guide
So, answering your question,
所以,回答你的问题,
Does this size limit include things such as the device token that have to be sent and other overhead information about the notification.
此大小限制是否包括诸如必须发送的设备令牌和有关通知的其他开销信息之类的内容。
Yes, this size limit includes device token and other overhead information.
是的,此大小限制包括设备令牌和其他开销信息。
Is the conversion 1 character = 1 byte or is it more than that.
转换是 1 个字符 = 1 个字节还是更多。
This is true if you're using only Latin letters in your notification.
如果您在通知中仅使用拉丁字母,则确实如此。
回答by tooluser
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.
以上都相当不清楚,因为“包含”可能意味着“它已经包含”或“您必须包含它”。非常清楚,设备 ID 是“元数据”,不是有效负载的一部分,也不会超出您的 256 个字符的预算。但是,另一个 APS 开销(标准负载字典)是。
Source: the above documentation plus experimentation to verify.
来源:以上文档加实验验证。
回答by firebear
In my APNS test in the production environment, up to 33 Chinese characters and 2 custom properties of 13 bytes could be sent successfully.
我在生产环境的APNS测试中,最多可以发送33个汉字和2个13字节的自定义属性。
{
"aps": {
"alert": "一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三",
"badge": 12,
}
"t": 123,
"v": "1234567890"
}
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).
如果保存为文件,上述有效载荷长度为 158 字节,不包括空格字符。每个汉字被算作 3 个字节(我通过删除所有它们来查看大小变化来确认)。
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.
正如官方文档所提到的,256 字节的限制不包括设备令牌,但我相信还有其他字符 APNS 被计算在内,例如“声音”和“内容可用”,即使您没有明确使用。
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.
所以要小心不要“太长”,尤其是在使用自定义有效负载时。请注意,APNS 开发环境不限制负载长度。您的测试在使用开发环境时通过,但在产品中可能会失败。不要认为它是肯定的。