iPhone Push Notification Character Limit

39,506

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

Solution 2

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.

Solution 3

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.

Share:
39,506
jcmitch
Author by

jcmitch

Updated on July 28, 2020

Comments

  • jcmitch
    jcmitch almost 4 years

    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.

  • jcmitch
    jcmitch over 12 years
    Okay since that does include the overhead do you know how much space I would have remaining after the overhead is taken into account? (Total space - Overhead = ? # of remaining characters) Thanks.
  • Andrey Zverev
    Andrey Zverev over 12 years
    considering the payload is minimal and only contains the alert information, you have about 236 characters for your text. But notice that push UIAlertView display limit is 107 characters. After that your message gets truncated and you will get a "..." at the end of the displayed message.
  • jcmitch
    jcmitch over 12 years
    Okay thanks. The UIAlertView shouldn't be a problem. Just need to attach data to be used later in the payload.
  • ostergaard
    ostergaard over 10 years
    @AndreyZ. - my tokens are 64 chars - how can there be 236 chars remaining if 256 doesn't include the token? :-S
  • tooluser
    tooluser over 10 years
    Given that 'include' can be understood both ways in all of the above, to be clear: the device ID is not taken out of your 256 character budget.
  • Marcin
    Marcin over 10 years
    It's not valid any more when you start localize push notifications, 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.
  • Ragunath Jawahar
    Ragunath Jawahar over 9 years
    iOS 8 has a 2KB limit, does that mean pre-iOS 8 devices can also receive push messages greater than 256 chars?
  • jcesarmobile
    jcesarmobile over 9 years
    @RagunathJawahar, I've been testing and I can receive 2KB on iOS 7 devices.
  • Ragunath Jawahar
    Ragunath Jawahar over 9 years
    @jcesarmobile Thank you for mentioning that :)