Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ionic 1 onesignal is there a way to know if there is a push notification when open app from background to foreground or launching app

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 ?

like image 969
Axil Avatar asked Feb 19 '18 09:02

Axil


2 Answers

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)

enter image description here

  1. It attracts the User
  2. Never distracts
  3. will be disappeared after the User has seen the notification
like image 188
Tummala Krishna Kishore Avatar answered Oct 13 '22 10:10

Tummala Krishna Kishore


You can try with https://github.com/katzer/cordova-plugin-background-mode

it helps you to Keep app running in background

like image 21
Manoj Bhardwaj Avatar answered Oct 13 '22 10:10

Manoj Bhardwaj