How to make ionic push notification triggers the app even in background?

626 Views Asked by At

i'm making a ionic app with ionic cloud push notifications.

Everything works well when the app is open, but i need to trigger some functions when the app receives a new notification even in the background, which it is not happening currently.

Plus, i want to send that notifications with content_available: 1, just to become invisible ones to the users, which leads into another problem, when the app is in background with this kind of notification, i don't have even the top menu alert to tap and open the app.

So, i want to know if it's possible to make a invisible push with content_available: 1 triggers a function inside my app while it's closed or asleep.

Thank you in advance.

2

There are 2 best solutions below

0
On

You can use cloud:push:notification event to catch each notification received to your application while it open, close or sleep.

sample code will describe the implementation. This link will also be helpful

 $rootScope.$on('cloud:push:notification', function(event, data) {
   $localStorage.pushNotification = data;
   var msg = data.message;
   /*When push notification open if application is in sleep state following code is given true*/
   var isAppSleep = msg.app.asleep;
   /*When push notification open if application is in closed state following code is given true*/
   var isAppClosed = msg.app.closed;

 });

0
On

See ParsePush Plugin :

 ParsePushPlugin.on('receivePN', function(pn){
       console.log('yo i got this push notification:' + JSON.stringify(pn));
   });

Or

 ParsePushPlugin.on('receivePN:chat', function(pn){
       console.log('yo i can also use custom event enter code here keep things like chat modularized');
   });