I have an ionic app made with ionic1 and using OneSignal for push notification. Currently, one signal works well for push notification when: - app is already open - app is in background or kill, clicking on the push notification
using these 2 functions handleNotificationReceived and handleNotificationOpened
window.plugins.OneSignal.handleNotificationReceived(function(jsonData) {
$state.go('panicalarm');
console.log("navigate to panicalarm page");
})
window.plugins.OneSignal.handleNotificationOpened(function(jsonData) {
$state.go('panicalarm');
console.log("navigate to panicalarm page");
})
I am wondering, how do i handle the push notification when launching the app directly or from bringing the app from background to foreground without clicking on the push notification ? Is that possible ?
i would say we can implement this in the following ways :
Solution 1: you can Send push notification every time . Then, if the app is open, ignore/swallow the notification. It seems like a waste of resource for me
Solution 2: Keep track of the app's state in your own database and only send a push notification if the app isn't transition from the background to foreground. It Seems to me overly complex.
My Proposed Solution :Will keep the same code for the foreground and background but when the app will be transition from the Background to the foreground i would be showing the notification icon (Badge Icon) like below (A sample one)
You can try with https://github.com/katzer/cordova-plugin-background-mode
it helps you to Keep app running in background
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With