0
votes

I currently have:

$payload = array();
$payload['aps']['badge'] = 1;
$payload['aps']['alert'] = html_entity_decode($title);
$payload['aps']['sound'] = "default";

But:

The maximum size allowed for a notification payload is 256 bytes; Apple Push Notification Service refuses any notification that exceeds this limit.

$title (is mainly english, not many special chars) is quite often larger than 256 chars. What should I do to check and limit/remove extra chars? strlen?

2
PHP string are kind of char arrays. IIRC a char is 1 byte long, so yeah: check with strlen if the string is larger than 256 chars. - clentfort

2 Answers

3
votes

You can either check with strlen if the title is bigger than 256, or just cut it. $title = substr($title, 0, 256);

1
votes

As it's described, the question is about length in bytes so substr is not the right method. I think that mb_strcut method should be used instead.

https://www.php.net/manual/en/function.mb-strcut.php