30
votes

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.

3

3 Answers

49
votes

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.

5
votes

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.

3
votes

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.