The real limits for the alert text are not documented anywhere.
The only thing the documentation says is:
In iOS 8 and later, the maximum size allowed for a notification payload is 2 kilobytes; Apple Push Notification Service refuses any notification that exceeds this limit. (Prior to iOS 8 and in OS X, the maximum payload size is 256 bytes.)
This is what I could find doing some experiments.
Alerts: Prior to iOS 7, the alerts display limit was 107 characters. Bigger messages were truncated and you would get a "..." at the end of the displayed message. With iOS 7 the limit seems to be increased to 235 characters. If you go over 8 lines your message will also get truncated.
Banners: Banners get truncated around 62 characters or 2 lines.
Notification Center: The messages in the notification center get truncated around 110 characters or 4 lines.
Lock Screen: Same as a notification center.
Just as a reminder here is a very good note from the official documentation:
If necessary, iOS truncates your message so that it fits well in each notification delivery style; for best results, you shouldn’t truncate your message.
It should be 236 bytes. There is no restriction on the size of the alert text as far as I know, but only the total payload size. So considering if the payload is minimal and only contains the alert information, it should look like:
{"aps":{"alert":""}}
That takes up 20 characters (20 bytes), leaving 236 bytes to put inside the alert string. With ASCII that will be 236 characters, and could be lesser with UTF8 and UTF16.
The limit of the enhanced format notifications is documented here.
It explicitly states:
The payload must not exceed 256 bytes and must not be null-terminated.
ascandroli claims above that they were able to send messages with 1400 characters. My own testing with the new notification format showed that a message just 1 byte over the 256 byte limit was rejected. Given that the docs are very explicit on this point I suggest it is safer to use 256 regardless of what you may be able to achieve experimentally as there is no guarantee Apple won't change it to 256 in the future.
As for the alert text itself, if you can fit it in the 256 total payload size then it will be displayed by iOS. They truncate the message that shows up on the status bar, but if you open the notification center, the entire message is there. It even renders newline characters \n.
The maximum size allowed for a notification payload depends on which provider API you employ.
When using the legacy binary interface, maximum payload size is 2KB (2048 bytes).
When using the HTTP/2 provider API, maximum payload size is 4KB (4096 bytes).
For Voice over Internet Protocol (VoIP) notifications, the maximum size is 5KB (5120 bytes)
OLD ANSWER:
According to the apple doc the payload for iOS 8 is 2 kilobytes (2048 bytes) and 256 bytes for iOS 7 and prior. (removed the link as it was an old doc and it's broken now)
So if you just send text you have 2028 (iOS 8+) or 236 (iOS 7-) characters available.
The Notification Payload
Each remote notification includes a payload. The payload contains
information about how the system should alert the user as well as any
custom data you provide. In iOS 8 and later, the maximum size allowed
for a notification payload is 2 kilobytes; Apple Push Notification
service refuses any notification that exceeds this limit. (Prior to
iOS 8 and in OS X, the maximum payload size is 256 bytes.)
But I've tested and you can send 2 kilobytes to iOS 7 devices too, even in production configurations
With iOS 8, Apple introduced new features that enable some rich new
use cases for mobile push notifications — interactive push
notifications, third party widgets, and larger (2 KB) payloads. Today,
we are pleased to announce support for the new mobile push
capabilities announced with iOS 8. We are publishing a new iOS 8
Sample App that demonstrates how these new features can be implemented
with SNS, and have also implemented support for larger 2KB payloads.
According to the WWDC 713_hd_whats_new_in_ios_notifications. The previous size limit of 256 bytes for a push payload has now been increased to 2 kilobytes for iOS 8.
"... When using the HTTP/2 provider API, maximum payload size is 4096
bytes. Using the legacy binary interface, maximum payload size is 2048
bytes. Apple Push Notification service (APNs) refuses any notification
that exceeds the maximum size."
每个远程通知都包含有效负载。有效负载包含有关系统应如何提醒用户的信息以及您提供的任何自定义数据。通知有效负载允许的最大大小取决于您使用的提供商 API。 使用 HTTP/2 提供程序 API 时,最大负载大小为 4096 字节。使用旧版二进制接口,最大有效负载大小为 2048 字节。 Apple 推送通知服务 (APN) 拒绝任何超过最大大小的通知。
Apple Updated Doc:
Each remote 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 depends on which provider API you employ. When using the HTTP/2 provider API, maximum payload size is 4096 bytes. Using the legacy binary interface, maximum payload size is 2048 bytes. Apple Push Notification service (APNs) refuses any notification that exceeds the maximum size.
发布评论
评论(11)
警报文本的真正限制没有记录在任何地方。
唯一的文档说是:
这是我在做一些实验时发现的。
在这里提醒一下,官方文档中有一个非常好的注释:
The real limits for the alert text are not documented anywhere.
The only thing the documentation says is:
This is what I could find doing some experiments.
Just as a reminder here is a very good note from the official documentation:
它应该是 236 字节。据我所知,警报文本的大小没有限制,只有总有效负载大小。因此,考虑到有效负载是否最小且仅包含警报信息,它应该如下所示:
占用 20 个字符(20 个字节),剩下 236 个字节放入警报字符串中。如果使用 ASCII,则为 236 个字符,如果使用 UTF8 和 UTF16,则可能会更少。
It should be 236 bytes. There is no restriction on the size of the alert text as far as I know, but only the total payload size. So considering if the payload is minimal and only contains the alert information, it should look like:
That takes up 20 characters (20 bytes), leaving 236 bytes to put inside the alert string. With ASCII that will be 236 characters, and could be lesser with UTF8 and UTF16.
增强格式通知的限制记录在此处。
它明确指出:
ascandroli 声称上述他们能够发送 1400 个字符的消息。我自己对新通知格式的测试表明,仅超出 256 字节限制 1 字节的消息就会被拒绝。鉴于文档在这一点上非常明确,我建议使用 256 更安全,无论您能够通过实验实现什么目标,因为不能保证 Apple 不会在未来将其更改为 256。未来。
至于警报文本本身,如果您可以将其容纳在 256 总负载大小中,那么 iOS 将显示它。它们会截断状态栏上显示的消息,但如果您打开通知中心,整个消息都在那里。它甚至呈现换行符
\n
。The limit of the enhanced format notifications is documented here.
It explicitly states:
ascandroli claims above that they were able to send messages with 1400 characters. My own testing with the new notification format showed that a message just 1 byte over the 256 byte limit was rejected. Given that the docs are very explicit on this point I suggest it is safer to use 256 regardless of what you may be able to achieve experimentally as there is no guarantee Apple won't change it to 256 in the future.
As for the alert text itself, if you can fit it in the 256 total payload size then it will be displayed by iOS. They truncate the message that shows up on the status bar, but if you open the notification center, the entire message is there. It even renders newline characters
\n
.编辑:
使用最新信息更新答案
通知有效负载允许的最大大小取决于您使用的提供商 API。
使用旧版二进制接口时,最大有效负载大小为 2KB(2048 字节)。
使用 HTTP/2 提供程序 API 时,最大负载大小为 4KB(4096 字节)。
对于互联网协议语音 (VoIP) 通知,最大大小为 5KB(5120 字节)
旧答案:
根据苹果文档,iOS 8 的有效负载为 2 KB(2048 字节),iOS 7 及更早版本为 256 字节。 (删除了链接,因为它是旧文档,现在已损坏)
因此,如果您只是发送文本,则可以使用 2028 个(iOS 8+)或 236 个(iOS 7-)个字符。
但我已经测试过,即使在生产配置中,您也可以向 iOS 7 设备发送 2 KB
EDIT:
Updating the answer with latest information
The maximum size allowed for a notification payload depends on which provider API you employ.
When using the legacy binary interface, maximum payload size is 2KB (2048 bytes).
When using the HTTP/2 provider API, maximum payload size is 4KB (4096 bytes).
For Voice over Internet Protocol (VoIP) notifications, the maximum size is 5KB (5120 bytes)
OLD ANSWER:
According to the apple doc the payload for iOS 8 is 2 kilobytes (2048 bytes) and 256 bytes for iOS 7 and prior. (removed the link as it was an old doc and it's broken now)
So if you just send text you have 2028 (iOS 8+) or 236 (iOS 7-) characters available.
But I've tested and you can send 2 kilobytes to iOS 7 devices too, even in production configurations
以下是一些屏幕截图(横幅、警报和通知中心)
Here're some screenshots (banner, alert, & notification center)
对于常规远程通知,最大大小为4KB(4096 字节)
https://developer.apple.com/library/ content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html
###iOS 大小限制为256 字节,但自从 iOS 8 推出后已更改为 2kb!https://forums.aws.amazon.com/ann.jspa?annID=2626
For regular remote notifications, the maximum size is 4KB (4096 bytes)
https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html
###iOS the size limit is 256 bytes, but since the introduction of iOS 8 has changed to 2kb!https://forums.aws.amazon.com/ann.jspa?annID=2626
根据 WWDC 713_hd_whats_new_in_ios_notifications。对于 iOS 8,推送负载的先前大小限制为 256 字节,现已增加至 2 KB。
来源:
http://asciiwwdc.com/2014/sessions/713?q=notification#1414.0
According to the WWDC 713_hd_whats_new_in_ios_notifications. The previous size limit of 256 bytes for a push payload has now been increased to 2 kilobytes for iOS 8.
Source:
http://asciiwwdc.com/2014/sessions/713?q=notification#1414.0
Apple 推送会因多种原因拒绝字符串。我测试了各种推送交付场景,这是我的工作修复(在 python 中):
Apple push will reject a string for a variety of reasons. I tested a variety of scenarios for push delivery, and this was my working fix (in python):
根据 更新的苹果文档(检查我的回答日期):
According to updated Apple document (check my answer date):
Apple 更新文档:
每个远程通知都包含有效负载。有效负载包含有关系统应如何提醒用户的信息以及您提供的任何自定义数据。通知有效负载允许的最大大小取决于您使用的提供商 API。 使用 HTTP/2 提供程序 API 时,最大负载大小为 4096 字节。使用旧版二进制接口,最大有效负载大小为 2048 字节。 Apple 推送通知服务 (APN) 拒绝任何超过最大大小的通知。
Apple Updated Doc:
Each remote 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 depends on which provider API you employ. When using the HTTP/2 provider API, maximum payload size is 4096 bytes. Using the legacy binary interface, maximum payload size is 2048 bytes. Apple Push Notification service (APNs) refuses any notification that exceeds the maximum size.
请参阅此处我的测试,
我最多可以发送 33 个中文字符和 13 个字节的自定义值。
see my test here
I could send up to 33 Chinese characters and 13 bytes of custom values.