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

191,013

Solution 1

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.

Solution 2

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.

Solution 3

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.

Solution 4

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

Solution 5

Here're some screenshots (banner, alert, & notification center)

AlertBannerNotification Center

Share:
191,013
hpique
Author by

hpique

iOS, Android & Mac developer. Founder of Robot Media. @hpique

Updated on January 04, 2020

Comments

  • hpique
    hpique over 4 years

    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, but surely there must be a specific character limit for the alert text.

  • dvs
    dvs almost 13 years
    Should be clarified that an in-app UIAlertView has no display limit; text over a certain length will go into a scroll view. An SMS or push alert probably has that 107-character limit, however.
  • Aaron Brager
    Aaron Brager over 10 years
    ASCII encoding violates the JSON spec, which requires UTF-8, UTF-16LE, UTF-16BE, UTF-32LE, or UTF-32BE. See ietf.org/rfc/rfc4627.txt; page 4.
  • Patrick Horn
    Patrick Horn over 10 years
    ASCII is a subset of UTF-8, so it is always safe to transmit 8-bit ASCII over the wire.
  • Marcin
    Marcin over 10 years
    And displayed text is not limited by payload, because when you use localization method it's no longer match 1:1. Payload may be short while final message may be much longer. The question is about displaying message it's not strictly related to payload maximum length.
  • Rup
    Rup about 10 years
    Thanks. I think the important bit is the reasoning behind 120, though - how did you get to that number? Would it be better to do the length truncation after the quotes and the newlines though, since that's a better representation of the length of the final string as sent to Apple?
  • DoctorDbx
    DoctorDbx almost 10 years
    I could send a huge payload to the sandbox and it would be delivered, but the production server was very restrictive to just 256 bytes and not one byte more.
  • klefevre
    klefevre almost 10 years
    @Diziet Sorry, I can't find an official note on that point but it has been officially announced while the last WWDC. Even Urban Airship annonced it : urbanairship.com/blog/2014/07/02/…
  • Diziet
    Diziet almost 10 years
    Here's the slides/video if anyone wants an apple link: developer.apple.com/videos/wwdc/2014 - Search "What's New in iOS Notifications"
  • Diziet
    Diziet almost 10 years
    @kl91 That's OK. Out of sync with the comments, I deleted my comment when I found the source. If you download the PDF it's on page 82.
  • Jing
    Jing over 9 years
    @kl94, so if the app still support targeting for iOS 7, will the 2kB size limit also apply to push notifications send to iOS 7 devices? Or the question is: is the new 2kB for all push notifications, no matter which platform it target to?
  • klefevre
    klefevre over 9 years
    @Jing We can optimistically think the new size limit will be apply to every platform.
  • harikrishnan
    harikrishnan almost 8 years
    can anyone tell the GCM Android push notif display text length ?
  • Hitendra Joshi
    Hitendra Joshi almost 8 years
    just curious, why you mentioned then It should be 236 bytes. ..I'm running with truncate issue..if I count total char length then it's not exceeding more then 1024 char, truncate alert message char length is 509 I'm receiving. What could be possible reason of truncate response. Any suggestion !!
  • CoDe
    CoDe over 7 years
    I still not able to receive payload size which is even less then 2KB. How this make sense when Apple say it increased to 5KB for VOIP. Any suggestion ?
  • CoDe
    CoDe over 7 years
    alert size that's true. But how this make sense where apple saying for VOIP it's size increased by 5KB. How this can be used. It still truncate payload size if it going beyond ~1KB. Any suggestion ?
  • jcesarmobile
    jcesarmobile almost 7 years
    Dear downvoter, if you downvote because of the links being broken, all the information is already here and it's correct, the link were only for reference. Also, it's good to comment why you donwvoted.
  • ssowri1
    ssowri1 almost 7 years
    Thank you! It's superb explanation.
  • Pedro Góes
    Pedro Góes over 6 years
    Thanks for your comment on removing all quotes, on iOS 11 it has a weird bug where it sounds the message but doesn't show anything.
  • vikram
    vikram almost 6 years
    1. For Voice over Internet Protocol (VoIP) notifications, the maximum payload size is 5 KB (5120 bytes). 2. For all other remote notifications, the maximum payload size is 4 KB (4096 bytes).