How to use push when the app is closed?


#1

I’m using the push plugin, and work’s perfectly when the app is open, but when the app is closed the method is not called…

My code look like this:

this.platform.ready().then(() => {
  console.log('Platform ready');
  this.initPush();
}

initPush() {
  let push = Push.init({
      android: {
          senderID: "XXXXXX"
      },
      ios: {
          alert: "true",
          badge: true,
          sound: 'false'
      },
      windows: {}
  });

  push.on('registration', (data) => {
      console.log("REGISTRATION");
          localStorage.setItem('token', data.registrationId);
  });

  push.on('notification', (data) => {
      console.log('ONLY WORK'S WHEN APP IS OPEN')
  });

  push.on('error', (e) => {
      console.log(e.message);
  });

}

How can I do to show the message from my push at any moment?

Thank’s!


Is it necessary background-mode for Push Notifications?
#2

Ionic is just browser. You need to use OS service (background process).


#3

My backend send the push, an this method is called, but only when the APP is open.
How I can call this method when the APP is closed?
I"m using the push plugin…
thx


#4

as mention by xr0master. you need to use background service. this is particularly because the ionic is a web application. so the javascript file will only be triggered/fired when you open the application. hope you understand. correct me if im wrong.


#5

How does it on Android?