iPhone 推送通知字符数限制

发布于 2025-01-03 17:59:04 字数 236 浏览 2 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

等往事风中吹 2025-01-10 17:59:04

每个推送通知都带有一个有效负载。有效载荷
指定如何提醒用户有待处理的数据
下载到客户端应用程序。允许的最大尺寸
通知负载为256字节;苹果推送通知服务
拒绝任何超出此限制的通知。

对于每个通知,提供者必须组成一个 JSON 字典对象
严格遵守 RFC 4627。该字典必须包含
另一个由键 aps 标识的字典。 aps词典
包含一个或多个指定以下操作的属性:

  • 向用户显示的警报消息
  • 用于标记应用程序图标的数字
  • 播放声音

-
本地和推送通知编程指南

所以,回答你的问题,

此大小限制是否包括诸如设备令牌之类的内容
要发送的信息以及有关通知的其他开销信息。

是的,此大小限制包括设备令牌和其他开销信息。

转换 1 个字符 = 1 个字节还是更多。

如果您在通知中仅使用拉丁字母,则情况确实如此。

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

-
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.

This is true if you're using only Latin letters in your notification.

氛圍 2025-01-10 17:59:04

上面的内容都相当不清楚,因为“包含”可能意味着“它已经包含”或“您必须包含它”。需要明确的是,设备 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.

萌︼了一个春 2025-01-10 17:59:04

我在生产环境的APNS测试中,最多可以成功发送33个汉字和2个13字节的自定义属性。

{

    "aps": {
        "alert": "一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三",
        "badge": 12,
    }
    "t": 123,
    "v": "1234567890"
}

如果保存为文件,上面的有效负载长度为 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.

{

    "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).

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.

后知后觉 2025-01-10 17:59:04

更新 2023

对于像我这样最近在 2023 年遇到这个问题的人,Apple 文档有关

基本的远程通知有效负载包括 Apple 定义的按键和
他们的自定义值。您还可以添加特定的自定义键和值
到您的通知。 Apple 推送通知服务 (APN) 拒绝
如果有效负载的总大小超过以下值,则会发出通知
限制:

对于互联网协议语音 (VoIP) 通知,最大
有效负载大小为 5 KB(5120 字节)。

对于所有其他远程通知,最大负载大小为 4 KB
(4096 字节)

Update 2023

For those, like me, who have come to this question recently, in 2023, Apple documentation about Generating a remote notification says:

A basic remote notification payload includes Apple-defined keys and
their custom values. You may also add custom keys and values specific
to your notifications. Apple Push Notification service (APNs) refuses
a notification if the total size of its payload exceeds the following
limits
:

For Voice over Internet Protocol (VoIP) notifications, the maximum
payload size is 5 KB (5120 bytes).

For all other remote notifications, the maximum payload size is 4 KB
(4096 bytes).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文