Push notifications open to specific state while app in background

I have an app with a chat component, and I would love users to be able to click on a new message push notification while my app is in the background and have the app open up and immediately go to the correct conversation.

This is easy for simple cases (onNotification, read the payload, run $state.go etc), where the app was moved to the background in a clean state. If the user was doing any of the following actions when they paused the app, then you have some hoops to jump through:

1. Plugins
If my user was using a plugin with a UI component like the camera or datepicker plugins, and the plugin was still visible when they paused the app, then the new state will open, but the plugin UI will be on top. Plugins have a .show() method, but they don’t normally have a .close() method. The user has to manually close it.

2. Modals
If the user had a modal open, then the new state will open, however the notification will be in the foreground. I am trying to handle this by broadcasting ‘closeAllModals’ in the onNotification method. Each modal controller then has an $on(‘closeAllModals’) event which checks if any modals are open and if so it calls modal.remove().

3. Popups
If any popups are open, then this will also appear over the new state. Once again, this can be handled with a broadcast to close the visible popups.

Does anyone have a better way of handing these issues? Is there any way to say that the modal/popup/plugin should only be visible while that particular view is the active view?

Hi @jack2, I’m looking to build a similar chat component. I haven’t built anything yet, so I’m still researching whether to use Parse, Ionic Push Alpha, ngCordova Push, or not use push notifications at all and instead use Twilio to simulate notifications via SMS.

I’m wondering which path you took—I’m assuming Ionic Push Alpha—and if you could point me to a good tutorial for implementing user-triggered push notifications. Caveat: I’m using Firebase as my data store, so I don’t have a server, and I’d prefer to avoid having to build one if possible.

Thanks!

I haven’t tested it yet but I believe this is the answer you looking for https://www.youtube.com/watch?v=bWUVgkMS2so

1 Like

Hi @jack2 What you are looking for is deep linking where a notification can redirect to specific view in your app,
Also i want to mention that push notification will be received by the app no matter what is your app state background of forground the differences is how the OS handle .

Hi, @stewartmccoy i just want to clear something for you that Pase and ionic push is push notification service providers when cordova push notification plugin is just a plugin that could be integrated with any push notification providers or also can be integrated with your push notification solution.

i also would like to mention push notification has many advantage over SMS to mention few (Cheaper, measurable (Analytics), customizable(you can send data to the app) )

1 Like

Thanks @adyba! Deep linking wasn’t an approach I had considered. Appreciate the helpful link :slight_smile:

Thank you @m2m for the clarifying details!