ngCordova LocalNotification plugin

2019-09-08 00:01发布

I'm using the ngCordova LocalNotification plugin in my Ionic app and I am trying to get it to repeat but with a random time span.

For example the user will trigger the notification to launch in 1 minute, and after that I would need to have the notification launched again in another 2 minutes (hypothetical example, in real life scenario the time span would be much higher, ie a couple days).

So far I can get the notification to execute for the first time.

Then, I am using the $cordovaLocalNotification:trigger method to detect when the notification was triggered and inside of that method I have a code to schedule a new notification.

All of this works, but in order to launch whatever it is inside of that method's body, I have to acknowledge the notification on my device and click on it, then it launches this method.

So I am wondering if there's a way to have it schedule a new notification without me having to open the previous notification?

All of this has to happen locally on the device and the notification should persist even if the device is rebooted. Thanks a lot!

1条回答
何必那么认真
2楼-- · 2019-09-08 00:46

When the application go in backround, the webview stops the javascript execution. When you click on the notification, the app became a foreground process and javascript continue the execution.

So it seems that it works only when you click on the notification (that open the app) because only when the app is opened, the js code is executed.

You could double check this if you don't click on the notification, opening the app after the notification is displayed (without clicking it).

To clear all the triggered notification you could use the getTriggeredIds(scope) method to get all triggered notification IDs and the clear(ids, scope) method to clear them.

See the localNotification plugin documentation for more information.

查看更多
登录 后发表回答