What is the maximum length of a Push Notification alert text?

后端 未结 11 1198
北海茫月
北海茫月 2020-11-30 16:28

What is the maximum length of the alert text of an iOS push notification?

The documentation states that the notification payload has to be under 256 bytes in total,

相关标签:
11条回答
  • 2020-11-30 17:22

    According to updated Apple document (check my answer date):

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

    0 讨论(0)
  • 2020-11-30 17:23

    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.

    0 讨论(0)
  • 2020-11-30 17:25

    see my test here

    I could send up to 33 Chinese characters and 13 bytes of custom values.

    0 讨论(0)
  • 2020-11-30 17:27

    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.

    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

    0 讨论(0)
  • 2020-11-30 17:28

    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.

    0 讨论(0)
提交回复
热议问题