Android can do it, what about iOS: can push-notification's payload be modified before it is shown to the user?

StackOverflow https://stackoverflow.com/questions/23476880

Question

Can one change push-notification's payload (say, to remove any BBCode) before it is seen by the user? Android can do this inside GCM's public class GcmIntentService extends IntentService. Is this feasible on iOS?

Was it helpful?

Solution

There's two types of push, "normal" and background - the latter is only available with iOS7.

  • If your app is not running in the foreground and a normal push is sent to it then the OS displays it to the user and your app has no involvement in that process so the payload cannot be modified. So in this situation the answer is no.

  • If your app is running in the foreground and a normal push is sent then the push is passed to the app, and the app can consume it and post a local notification with whatever payload it wants. To a user a local notification and a push notification look the same, the user cannot distinguish between them. So in this situation the answer is not literally yes but effectively yes.

  • If the app is running in the foreground or the background and a background push is sent to it then the app receives it and can consume it and post a local notification. So in this situation the answer is also not literally yes but effectively yes.

  • If the app has been terminated by the user and a background push is sent to it then neither the app will receive it nor will it be displayed to the user.

  • If the app has been terminated by the user and a normal push is sent to it then it will be displayed to the user, with no involvement from the app.

  • If the app is in the foreground or background and a background push is sent to it while the user is on a phone call then the app will not receive the push nor will it be displayed to the user.

OTHER TIPS

You don't have to change the payload before it is seen by the user. You can simply determine in advance (in the server side) which parts of the notification will be displayed, and which not.

The part of the notification payload that is displayed to the user is the alert field within the aps dictionary of the JSON payload. You can pass additional custom data outside the aps dictionary, that will be passed to your app (only if the app was running in the foreground when the notification arrived, or it wasn't running and the user tapped the notification to open the app) and won't be displayed to the user.

For example :

{

    "aps" : {

        "alert" : "shown to the user"
    },

    "custom_parameter" : "not shown to the user"

}

See here for more about the notification payload.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top