Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I send an Apple Push Notification with multiple lines i.e. with a '\n' character?

I would like to know how to send an apple push notification message with multiple lines. Using '\n' doesn't seem to work.

Something like:

First line

Second Line

Right now it seems to just ignore the message altogether.

like image 756
rmontgomery429 Avatar asked Oct 09 '11 21:10

rmontgomery429


People also ask

How many characters can a push notification have?

Push notifications have word boundations. Meaning, their title cannot exceed a character limit of about 48 characters; copy content limits to 100 characters; and a call-to-action button.

What is maximum characters for push notifications iOS?

iOS push notification character limits are 110 characters for both iOS lock screen and notification center. That's about 4 lines of text.

How do I push Apple notifications?

An iOS push notification is a message that pops up on an Apple device such as an iPhone. Before receiving push notifications from an app, iOS device users must explicitly give permission. Once a user opts-in, mobile app publishers can send push notifications to the users' mobile devices.


2 Answers

You cannot send multi line push with a escape, it will not work!

simply tried to send push with Parse:

Payload without an escape:

{ "alert": "Send me\na push without escape", "sound": "default" }

Result: enter image description here

Payload with an escape

{ "alert": "Send me\\na push with escape", "sound": "default" }

Result:

enter image description here

like image 169
Johnny Avatar answered Nov 29 '22 10:11

Johnny


Add a localizable strings file and add your string there. For example, you could have something like:

"Push_String" = "My push string with a line break\n and argument: %@";

Now in your notification payload, use the loc-key and loc-args properties, for example:

"loc-key":"Push_String","loc-args":["My argument!"]

Now you should have a line break in your notification.

like image 26
egarc Avatar answered Nov 29 '22 08:11

egarc