Updating Pushes
In current Sailthru Mobile SDKs, collapse_key
can be used to update pushes on the client side. For this to work, both the push to be updated and the push updating it must have the collapse_key
.
Example 1: Fixing a typo
If we were to accidentally sent a push with a typo:curl -X POST -u :API_KEY -H "Content-type: application/json" -H 'Accept: application/json' https://api.carnivalmobile.com/v5/notifications -d ' {
"notification": {
"to": "*",
"payload": {
"alert": "Greg deals on the new iPhone!",
"collapse_key": "foobar"
}
}
}'
We could then fix the typo by sending a new push to the same audience with the same collapse_key
:
curl -X POST -u :API_KEY -H "Content-type: application/json" -H 'Accept: application/json' https://api.carnivalmobile.com/v5/notifications -d ' {
"notification": {
"to": "*",
"payload": {
"alert": "Great deals on the new iPhone!",
"collapse_key": "foobar"
}
}
}'
This new push would arrive at user’s devices, and replace the existing one. It will, however, still alert the user in whatever ways it’s set up to when it arrives – sounds, vibration, lights, etc.
Example 2: Only ever showing one notification
It can be all too easy to clutter your user’s notification trays with alerts, so you might want to only ever show one notification in your users tray. . A push with acollapse_key
will only replace another notification if it’s already in the tray – if there’s nothing to replace, then the push will just show up like normal
To make sure only one notification ever shows at a time, give every notification the same collapse_key
. This means that if there’s a notification in the tray, the incoming one will replace it. If there’s no notification from your app in the tray, then it’ll show up like normal.