简体   繁体   English

从后台安排本地通知(Ionic + ngCordova)

[英]Scheduling local notifications from the background (Ionic + ngCordova)

I am using the ngCordova LocalNotification plugin in my Ionic app to schedule the notifications on the device and deliver them locally. 我在Ionic应用程序中使用ngCordova LocalNotification插件来安排设备上的通知并将其发送到本地。 My app requires to schedule a new notification every time the previous one is delivered. 我的应用要求每次发送前一条通知时安排新的通知。

I am using the $cordovaLocalNotification:trigger method to schedule another notification upon receiving the last one. 我正在使用$ cordovaLocalNotification:trigger方法在收到最后一个通知时安排另一个通知。 Everything works fine as long as I respond to the received notification and click on it. 只要我响应收到的通知并单击它,一切就可以正常工作。 If I simply clear or ignore the notification, no new notification is scheduled and subsequently delivered. 如果我只是清除或忽略该通知,则不会安排新的通知,也不会随后发送新的通知。

So far I managed to figure out that the problem is that the call is registered only when the app is brought to the foreground. 到目前为止,我设法弄清楚问题是仅在将应用程序置于前台时才注册呼叫。 So I am wondering how to execute my code when the app is in the background? 所以我想知道当应用程序在后台时如何执行我的代码吗? Obviously, I cannot expect every user to reply to every notification in order to schedule the new one. 显然,我不能期望每个用户都可以答复每个通知以安排新的通知。

Thanks a lot. 非常感谢。

There at least two different cordova plugins to do this: 至少有两个不同的cordova插件可以做到这一点:

The first allow you to execute code while the application is in background, while the second transform your app in a service. 第一个允许您在应用程序处于后台时执行代码,第二个允许您在服务中转换应用程序。

Look at this example of the first plugin to know how to execute code in background. 查看第一个插件的示例 ,以了解如何在后台执行代码。

In your specific case, you should listen for the trigger event in the background code. 在特定情况下,您应该在后台代码中侦听触发事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM