Should I use $cordovaPush for 'Push notification received'?

Hello.
I want to make notification feature and connect to badge.

Once user gets notification then the number of badge increase.

I followed this link for push http://docs.ionic.io/docs/push-usage

and I use $cordovaBadge for badge.

Each work fine.

But I realise that “onNotification” method only works when app is running.

I found out $cordovaPush and ‘$cordovaPush:notificationReceived’ seems may working even app is not running ( I did not test yet )

Is there only one way to catch ‘notification received’ event even app is not running?

Thanks

Well … you first need to know/learn … you have the part of the OS (device) and your code. I’m using IOS as example and the push plugin (http://ngcordova.com/docs/plugins/pushNotifications/)

So what does this means. In your app, you need to register for push to obtain the devicetoken. The registration has some options like “alert”, “sound” , “badge” . So when you send out a notification, you can specify the badge counter.

When your app is not running, the device will take over and it will automaticly add the badge number. I’m not sure if the device will alter the badge number when you’re in the app (app is active) and you will recieve the notification. But then ‘$cordovaPush:notificationReceived’ will come in action (with the notification payload).

well that’s my experience :slight_smile:

1 Like

Also … when your app is not running and you get the notification and you tap on the notification, the device will start your app AND fire the $cordovaPush:notificationReceived so your code can react on it.

Thank you for quick response. That’s what exactly wanted.

By the way, I followed this tutorial.

And I could see that it makes me to download ‘phonegap-plugin-push’ which is not '$cordovaPush’
Preferably I don’t want to change to another plugin but, ‘phonegap-plugin-push’ seems does not have notification method which even working when app is not running.

I’ve got push notifications with $ionicPush working successfully, but the handler is not called while the app is closed nor does the badge update. Would you mind posting your .register() method so I can see what I’m doing wrong?

Hello.
I end up with changing notification plugin.
Now am using Phonegap-plugin-push
I think this is simpler.

1 Like