Best way to make conditional notification?

Hello I’m new with ionic 2.
I have an application who retrieve many data from a database through http request.
Users of my app can actually set favorite data that they want to see on the top.
I would like that when a data change all the users who have this data in favorite have a notification on their phone even when the application is not running.

What is the best way to do this?

If you want to notify all users, also the ones currently not active, on a change done on the backend side (in the database) you have to trigger sending the notification on the backend, too. Basically you just call an URL that sends a push. Of course to know which users to push to, you also have to inform the backend that these users favorited this item, so this has to be persisted and sent back to your backend, too.

thank you for you answer.
But I don’t have the informations of the favorites of all the user because they are stocked locally and the app don’t have registering system of user.
Is there a way for a local treatment of the push notification like this? :

  • data in db change
  • notification push send to all users
  • app receive push notification check if the data is in the local favorite
  • if the data is in the local favorite show the notification

Depending on what you mean by “show the notification”.

Problem is that when you send a notification and the app is not open, it will be handled by the OS and shown in the notification center. When the user then opens the app, the OS sends the notification data it received earlier to the app so the app can handle it.

There may be a way to send “silent” notifications that only transmit data, but then you can’t really do the “check if user favorited this item” thing because the app is closed. You could only do this later when he opens the app (without seeing a notification earlier) and then show him a notice that the item changed.

You will have to somehow tell the backend who favorited what.

show the notification is show the alert “hey a data have changed” to the telephone user.
when you said app closed you mean “app not in first plan” or “app killed in active processus”?

Alerts are shown in apps.

On OS it is this way: When the app is not in front of the user at the time the notification arrives it is display in different ways depending on the OS: iOS users will see a “flyin” from the top if they are using the device, if it is locked it will be added straight to the notification center. On Android I am not sure, I don’t think there are flyins there but a small icon in the top bar and same for locked device straigt to notification center.

I am not sure if this makes a difference here. I mostly meant “not in foreground”.

ok thank you for the answers

1 Like