How can I send an Apple Push notification with multiple lines, i.e. with the character '\ n'?

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

Sort of:

First line

Second line

At the moment, it simply ignores the message at all.

+5
source share
8 answers

Add a localizable string file and add your own string there. For example, you might 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!"]

You should now have a line break in your notification.

+3
source

push , !

push Parse:

:

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

: enter image description here

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

:

enter image description here

+3

, !

\r\n

+2

Apple push . push-, ( python):

#  Apple rejects push payloads > 256 bytes (truncate msg to < 120 bytes to be safe)
if len(push_str) > 120:
    push_str = push_str[0:120-3] + '...'

# Apple push rejects all quotes, remove them
import re
push_str = re.sub("[\"']", '', push_str)

# Apple push needs to newlines escaped
import MySQLdb
push_str = MySQLdb.escape_string(push_str)

# send it
import APNSWrapper
wrapper = APNSWrapper.APNSNotificationWrapper(certificate=...)
message = APNSWrapper.APNSNotification()
message.token(...)
message.badge(1)
message.alert(push_str)
message.sound("default")
wrapper.append(message)
wrapper.notify()
+1

, :

string = "first line  \r\n Second line ";
+1

chr (10) PHP push-, .

$message = "Hey {user_firstname}! " . chr(10) . "you have a new message!"

+1

: esacpae the\n. Duh.

:

First line \\n
Second Line

First line \n
Second Line
0

:

alert:"this is 1st line \\n"
0

All Articles