reload the app while receiving specific notification

hi , im wondering how can i reload the app while receiving a specific notification. while sending the notification i have set a custom payload.

the code below dont work

	push.onReceivedMessage = function(payload) {
		if(payload.payload == "message"){
reloadMessage()
}
     };

Do you mean reload like the simulator? A reload of the app can only be triggered by the tooling for now. What is the usecase for this?

This is the first time i use notification system to run a function to refresh data (i was using realtime data with firebase ) so i dont entirely understand how it works.
what i want to do is separate notification by payload name and run function regarding payload of the notification arriving.

if i send a message , the payload set will be message , while receiving the notification i want to be able to just run the message function to refresh the data and follow the same pattern with all others function

Hey Kobo,
I believe it would help you to understand that you have full control over what you put inside the push notification payload. It’s not really restricted to something predefined.

So, for example, one way to handle what you want to achieve would be to send a push notification with a payload like this:

{
  "aps":{
    "alert":{
      "title":"notification title",
      "body":"notification body"
    },
    "data":{
      "type":"message",
      "content":"message content"
    }
  }
}

What happens with this when the phone receives the notification is - the title and body params under alert are used by the phone OS to display the notification, hence you should always send these when you want to deliver a visible notification.

Now, when notification is delivered to your push.onReceivedMessage function, you get the whole object, so you can start acting on what’s inside of that data element.

Note that this is also a way for you to deliver a “silent” notification, if you omit the alert element. So, theoretically, you should be able to do this:

{
  "aps":{
    "data":{
      "type":"restart",
      "content":"because I said so"
    }
  }
}

With all of the above in mind, you could then do the following in JS:

push.onReceivedMessage = function(payload) {
  var obj = JSON.parse(payload);
  switch (obj.aps.data.type) {
    case 'message':
      // do something with messages
    break;
    case 'restart':
      // do something else
    break;
  }
};

Hope this helps!

Many thanks uldis for your explanation, perfectly what i was looking for :slight_smile: