简体   繁体   中英

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. 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. 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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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