iOS Push Notification ios-alert in JSON

Hi can you please post example how to send APNS payload in JSON.

For example this payload:

let alertPayload =
{
    "title":"Add Goods Offer",
    "loc-key":"",
    "loc-args":[result.client.name,result.goods.name,result.price]
};

I want to add to:

let publishOption = new PublishOptions({
    "headers": {
        "client-objectId": result.client.objectId,
        "objectId":result.objectId,
        "message-type":302,
        "ios-alert": alertPayload,
        "ios-category":"AddGoodsOfferCategory",
        "ios-sound":"default"
    }
});

But I am receiving:‘Wrong json format: Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: N/A; line: -1, column: -1] (through reference chain: com.backendless.messaging.PublishMessageInfo[“headers”]->java.util.LinkedHashMap[“ios-alert”])’ }Can i use keys like:ios-alert-title-loc ? How we should use nested objects in header ?Or how exacly I should send localized push notifications with params ?!

Hi Tomas,

Please refer to below video guide, hope it will help you -
https://backendless.com/category/push-notification/

There is no reference about question I asked in that video

From documentation: we can use - “ios-alert”:value
Also under this link you can find useful information related to your issue -

https://backendless.com/documentation/messaging/ios/messaging_publish_push_notifications.htm

Yeah, thank you for link, I can read documentation too and as you can see I already implemented push notifications which works just fine. But according to docs:

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.7px Helvetica; -webkit-text-stroke: #000000}
span.s1 {font-kerning: none}

OS
“ios-alert”:value
Sets the text of the alert message. If the header is not present and the published notification targets the iOS devices, Backendless sets the header to the value of the “message” argument. To disable this behavior, set the ios-alert header to null.

And According to apple docs APN -> Alert can be String OR Dictionary with number of key/values
I am asking how to setup ios-alert key to dictionary!

Anyone?

Hi Tomas,

In the commit history I can see that the fix has been done a few days ago, but I’m not sure if it’s already available on the online server. Can you please try the same request again and tell us whether it still doesn’t work as expected?

Object approach:

let alertPayload =
{
 "title":"Add Goods Offer",
 "loc-key":"AddGoodsOfferMessage",
 "loc-args":[result.client.name,result.goods.name,result.price]
};
let publishOption = new PublishOptions({
 "headers": {
 "client-objectId": result.client.objectId,
 "objectId":result.objectId,
 "message-type":302,
 "ios-alert": alertPayload,
 "ios-category":"AddGoodsOfferCategory",
 "ios-sound":"default"
 }
});

{ code: 5010,

message: ‘Wrong json format: Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: N/A; line: -1, column: -1] (through reference chain: com.backendless.messaging.PublishMessageInfo[“headers”]->java.util.LinkedHashMap[“ios-alert”])’ }

Using key-value approach

let publishOption = new PublishOptions({
 "headers": {
 "client-objectId": result.client.objectId,
 "objectId":result.objectId,
 "message-type":302,
 "ios-alert-title": "Add Goods Offer",
 "ios-alert-loc-key": "Add Goods Offer",
 "ios-alert-loc-args": JSON.stringify([result.client.name,result.goods.name,result.price]),
 "ios-category":"AddGoodsOfferCategory",
 "ios-sound":"default"
 }
});

Does not use title, loc key/args but instead it will use string passed in publish method!

So please provide documentation how to pass dictionary value to ios-alert header OR allow string value to be parsed as dictionary…

Hi Tomas.
Please setup is-alert as mentioned below:

“ios-alert”:value
Sets the text of the alert message. If the header is not present and the published notification targets the iOS devices, Backendless sets the header to the value of the “message” argument. To disable this behavior, set the ios-alert header to null.

Sorry but did you read the question ?!

As I said, pure string ie. message is working! BUT alert header on APNS side can take dictionary is well = key-value pairs with a lot of features. Some of them are already implemented on backendless such as ios-category but not all of them. And this solution might not be viable in the future as well (in case of changing keys/add new keys)

So I am asking to provide working solution to pass dictionary to ios-alert

Any progress ?!

Apple Docs:

Child properties of the alert propertyKey
Value type
Comment
title
String
A short string describing the purpose of the notification. Apple Watch displays this string as part of the notification interface. This string is displayed only briefly and should be crafted so that it can be understood quickly. This key was added in iOS 8.2.
body
String
The text of the alert message.
title-loc-key
String or null
The key to a title string in the Localizable.strings file for the current localization. The key string can be formatted with %@ and %n$@ specifiers to take the variables specified in the title-loc-argsarray. See [url=https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW9]Localizing the Content of Your Remote Notifications[/url] for more information. This key was added in iOS 8.2.
title-loc-args
Array of strings or null
Variable string values to appear in place of the format specifiers in title-loc-key. See [url=https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW9]Localizing the Content of Your Remote Notifications[/url] for more information. This key was added in iOS 8.2.
action-loc-key
String or null
If a string is specified, the system displays an alert that includes the Close and View buttons. The string is used as a key to get a localized string in the current localization to use for the right button’s title instead of “View”. See [url=https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW9]Localizing the Content of Your Remote Notifications[/url] for more information.
loc-key
String
A key to an alert-message string in a Localizable.strings file for the current localization (which is set by the user’s language preference). The key string can be formatted with %@ and %n$@ specifiers to take the variables specified in the loc-args array. See [url=https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW9]Localizing the Content of Your Remote Notifications[/url] for more information.
loc-args
Array of strings
Variable string values to appear in place of the format specifiers in loc-key. See [url=https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW9]Localizing the Content of Your Remote Notifications[/url] for more information.
launch-image
String
The filename of an image file in the app bundle, with or without the filename extension. The image is used as the launch image when users tap the action button or move the action slider. If this property is not specified, the system either uses the previous snapshot, uses the image identified by the UILaunchImageFile key in the app’s Info.plist file, or falls back to Default.png.

What about progress ? I see that there is same messaging API structure in v 4.0+ as well :frowning:

How can we send Rich notifications then ?

Wouldn’t be easier to just leave it to client to pass whole APNs/FCM json object than using your key-values ?

Tomas,

Rich notifications are planned to be added in 4.1, right now we are focusing on getting the product out of beta.

Regards,
Mark