Reputation: 187
All,
I am sending push notifications with data in a string. Example:
{
"aps": {
"alert": "1,FriendsName,3,4,pink, green",
"sound": "default"
}
}
or
{
"aps": {
"alert": "2,drinks, adress",
"sound": "default"
}
}
Now, I want the message in the alert to show a text, based on the values in the string.
So (pseudo-code):
if the first character in "alert" = 1 => "alert = @"Color from %@ is %@", friendsName, pink
if the first character in "alert" = 2 => `"alert = @"Invite for %@ at %@", drinks, adress
Is this possible at all? And if so: how?
Upvotes: 2
Views: 1493
Reputation: 69469
No this is not possible in the way you want. iOS handles the push notification and your app has no influence on the way the notification is presented. iOS will just present what you send in the notification.
However you can use localization to achieve what you want:
"alert" : { "loc-key" : "ALERT_FORMAT", "loc-args" : [ "FriendsName", "pink"] },
Where the ALERT_FORMAT
is a localization in you Localizable.strings
file:
"ALERT_FORMAT" = "Color from %@ is %@"
But you will have to change the type of notification on the server, so the notification you send it an invite you will need to change the notification on the server.
So you will send something like this for the invite:
"alert" : { "loc-key" : "ALERT_INVITE", "loc-args" : [ "drinks", "adress"] },
Where the ALERT_INVITE
is a localization in you Localizable.strings
file:
"ALERT_INVITE" = "Invite for %@ at %@"
So you JSON for the push notification should look like:
{
alert" : {
"loc-key" : "ALERT_FORMAT",
"loc-args" : [ "FriendsName", "pink"]
}
}
Upvotes: 2