1
votes

For sending push notifications, we have used Amazon Simple Notification Service (Amazon SNS). When I test push notification by sending characters around 80, I get push notification but when characters exceeds 80 or 85, notifications are not delivered.

We have limits of 256 bytes for payload but I don't think it may exceed that limit if I send that much of characters. At-least messages should truncated.

I have found that:

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.

But in my case, I don't even get notification. Is it something related to Amazon SNS ? Am I missing something to check ?

EDIT 1:

I am not attaching image or anything with text message. I just send plain text message.

EDIT 2:

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

I am having device which has iOS 9 installed. So for that device, 2000 Bytes are far more limit than 80-85 characters including payload size.

I am really desperate about what I am missing ?

1
You should remember that the 256 bytes limit is for the entire payload, so not only your message but also everything else - the payload is in JSON format, so keys, and all special characters also count to the limit. - Losiowaty
Thanks @Losiowaty, this adds something to my knowledge. Now apart from that JSON, what may be the thing that is increasing the size? Actually I don't have perfect idea about server data.. - NSPratik

1 Answers

2
votes

You should remember that the 256 bytes limit is for the entire payload, so not only your message but also everything else - the payload is in JSON format, so keys, and all special characters also count to the limit.

This is the minimal payload required by Apple to be considered correct :

{
    "aps" : {
        "alert" : "your text"
    }
}

So we already "loose" 19 bytes, to send a simple notification. If we want to have also a custom title :

{
    "aps" : {
        "alert" : {
            "title" : "your title",
            "body" : "your text"
        }
    }
}

This adds up to 40 "lost" bytes (about 15%). Adding custom sounds and badges will also decrease the count left for the actual message.

Now, these bytes are lost only due to the required keys, and there is not much you can do about it. I haven't used Amazon SNS, but they may be adding some custom fields for their own purposes, leaving you with less space for the message. You can inspect this in your didReceiveRemoteNotification method by inspecting the userInfo dictionary. Simple NSLog(@"userInfo -> %@", userInfo) should dump all contents to the console. This representation won't be 1:1 with the JSON in terms of extra characters, but will give you and idea of what else, if anything, apart from the required fields is sent.

Other thing worth mentioning is that non-ASCII characters will take more than one byte of space, so you can effectively use fewer characters for your message.