如何制作离子推送通知甚至在后台触发应用程序?

时间:2016-11-14 18:35:37

标签: android ionic-framework push-notification phonegap-pushplugin ionic-cloud

我正在使用离子云推送通知制作离子应用程序。

当应用程序处于打开状态时,一切正常,但是当应用程序收到新通知时,我需要触发一些功能,即使在后台也是如此,目前还没有这样做。

另外,我想发送带有content_available的通知:1,只是为了成为隐形的用户,这导致另一个问题,当应用程序处于此类通知的后台时,我没有甚至顶部菜单提醒点击并打开应用程序。

所以,我想知道是否可以使用content_available进行隐形推送:1在我的应用程序关闭或睡眠时触发一个功能。

提前谢谢。

2 个答案:

答案 0 :(得分:0)

请参阅ParsePush插件:

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

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

答案 1 :(得分:0)

您可以使用cloud:push:notification事件来捕获应用程序在打开,关闭或睡眠时收到的每个通知。

示例代码将描述实现。 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;

 });