Ionic event handling

Hi All,

My query is more about best practice or the right way to handle events in an ionic app.
Say my app has 2 events viz. notification event and login event. Whenever a user signs up, login event is triggered which takes the action to next page say "home page"
Also whenever the app starts there is a watcher which checks for user already logged in (like in firebase which does not require the user to relinquish) and fires the login event
Now let’s say there is a notification event which takes the control to say notification page.

Let’s assume that the app is not running and there is a notification. User click on the notification awakes the app and app initialization is triggered

Now there is a notification event and a login event, both of events will be triggered.

The query is what is the right way to handle such situations. Any pointers on the sample app/code with the best practices will be really helpful

Thanks and regards
Dhaval Shah

Depends on the logic of your app.

Is the notification bound to a user? Then of course only go there if the user is also logged in.
If the user is coming back, and there is no other way to get to the notification page, go there.
If there is another way, maybe don’t got there.

The underlying problem is, I think, this logic of going to a page when a notifications comes in. I definitely would not like that to happen when I am using an app.

Thanks for the reply

Spot on. The problem is because I want user to land on certain page when a certain notification is clicked.
This was with the intent of deep linking… And taking the user where notification is relevant.
But I would love to know how would you have approached the same problem.

Regards
Dhaval Shah

Is it only on clicking the notification that the user gets redirected to that page or also if he already is using the app at the time the notification comes in?

If the user is already using the app, then an alert with a prompt should appear. Next action depends on choice made by the user in alert box. I don’t want to abruptly take user somewhere just because a notification has arrived disturbing his current activity. In other case user is invoking the app with the intention of acting on notification.

1 Like

Ok, then you have all the cases, right? When a user opens the app via the notification directly, go to the notification page. When he does not, show the alert on the LoggedIn page as you would if he was using the app when the notification arrived.

But the problem still persists. When the user opens the app via notification, there are 2 events being triggered simultaneously viz. Login and Notification. How would you handle this situation, as there could be a normal login event when the app is opened without the notification being clicked.

If opened via notifications the code in the notification event first has to check if user is actually logged in (same user as who notification is for). If same user, show notification. (Login event would do unsurprising thing so can be ignored) Right?