Notification should happen once only on trigger time
Notifcation non-stop fire repeatedly in about 5 minutes then stop
This is my code in app.js. I use ionic v1 with ngCordova
```.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
cordova.plugins.notification.local.schedule({
id: 1,
title: 'test title',
text: 'test description',
trigger: { every: {hour: 10, minute: 0, second: 0} }
});
## Context
Fire notication at specific hour every day like 10 am and 4pm every day
## Debug logs
_Include Android logs_
12-14 04:06:04.015 30007-30007/io.ionic.starter D/CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.core.fireEvent("trigger",{"id":1,"title":"test title","trigger":{"every":{"hour":4,"minute":5,"second":0},"type":"calendar"},"actions":[],"attachments":[],"autoClear":true,"defaults":0,"foreground":false,"groupSummary":false,"launch":true,"led":true,"lockscreen":true,"number":0,"priority":0,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"showWhen":true,"silent":false,"smallIcon":"res:\/\/icon","sound":true,"text":"","vibrate":false,"wakeup":true,"meta":{"plugin":"cordova-plugin-local-notifications","version":"0.9-beta"}},{"event":"trigger","foreground":true,"queued":false,"notification":1}))
12-14 04:06:04.017 30007-30007/io.ionic.starter D/CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.core.fireEvent("trigger",{"id":1,"title":"test title","trigger":{"every":{"hour":4,"minute":5,"second":0},"type":"calendar"},"actions":[],"attachments":[],"autoClear":true,"defaults":0,"foreground":false,"groupSummary":false,"launch":true,"led":true,"lockscreen":true,"number":0,"priority":0,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"showWhen":true,"silent":false,"smallIcon":"res:\/\/icon","sound":true,"text":"","vibrate":false,"wakeup":true,"meta":{"plugin":"cordova-plugin-local-notifications","version":"0.9-beta"}},{"event":"trigger","foreground":true,"queued":false,"notification":1}))
12-14 04:06:04.018 30007-30007/io.ionic.starter D/CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.core.fireEvent("trigger",{"id":1,"title":"test title","trigger":{"every":{"hour":4,"minute":5,"second":0},"type":"calendar"},"actions":[],"attachments":[],"autoClear":true,"defaults":0,"foreground":false,"groupSummary":false,"launch":true,"led":true,"lockscreen":true,"number":0,"priority":0,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"showWhen":true,"silent":false,"smallIcon":"res:\/\/icon","sound":true,"text":"","vibrate":false,"wakeup":true,"meta":{"plugin":"cordova-plugin-local-notifications","version":"0.9-beta"}},{"event":"trigger","foreground":true,"queued":false,"notification":1}))
12-14 04:06:04.019 30007-30007/io.ionic.starter D/CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.core.fireEvent("trigger",{"id":1,"title":"test title","trigger":{"every":{"hour":4,"minute":5,"second":0},"type":"calendar"},"actions":[],"attachments":[],"autoClear":true,"defaults":0,"foreground":false,"groupSummary":false,"launch":true,"led":true,"lockscreen":true,"number":0,"priority":0,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"showWhen":true,"silent":false,"smallIcon":"res:\/\/icon","sound":true,"text":"","vibrate":false,"wakeup":true,"meta":{"plugin":"cordova-plugin-local-notifications","version":"0.9-beta"}},{"event":"trigger","foreground":true,"queued":false,"notification":1}))
12-14 04:06:04.020 30007-30007/io.ionic.starter D/CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.core.fireEvent("trigger",{"id":1,"title":"test title","trigger":{"every":{"hour":4,"minute":5,"second":0},"type":"calendar"},"actions":[],"attachments":[],"autoClear":true,"defaults":0,"foreground":false,"groupSummary":false,"launch":true,"led":true,"lockscreen":true,"number":0,"priority":0,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"showWhen":true,"silent":false,"smallIcon":"res:\/\/icon","sound":true,"text":"","vibrate":false,"wakeup":true,"meta":{"plugin":"cordova-plugin-local-notifications","version":"0.9-beta"}},{"event":"trigger","foreground":true,"queued":false,"notification":1}))
12-14 04:06:04.021 30007-30007/io.ionic.starter D/CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.core.fireEvent("trigger",{"id":1,"title":"test title","trigger":{"every":{"hour":4,"minute":5,"second":0},"type":"calendar"},"actions":[],"attachments":[],"autoClear":true,"defaults":0,"foreground":false,"groupSummary":false,"launch":true,"led":true,"lockscreen":true,"number":0,"priority":0,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"showWhen":true,"silent":false,"smallIcon":"res:\/\/icon","sound":true,"text":"","vibrate":false,"wakeup":true,"meta":{"plugin":"cordova-plugin-local-notifications","version":"0.9-beta"}},{"event":"trigger","foreground":true,"queued":false,"notification":1}))
12-14 04:06:04.022 30007-30007/io.ionic.starter D/CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.core.fireEvent("trigger",{"id":1,"title":"test title","trigger":{"every":{"hour":4,"minute":5,"second":0},"type":"calendar"},"actions":[],"attachments":[],"autoClear":true,"defaults":0,"foreground":false,"groupSummary":false,"launch":true,"led":true,"lockscreen":true,"number":0,"priority":0,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"showWhen":true,"silent":false,"smallIcon":"res:\/\/icon","sound":true,"text":"","vibrate":false,"wakeup":true,"meta":{"plugin":"cordova-plugin-local-notifications","version":"0.9-beta"}},{"event":"trigger","foreground":true,"queued":false,"notification":1}))
12-14 04:06:04.023 30007-30007/io.ionic.starter D/CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.core.fireEvent("trigger",{"id":1,"title":"test title","trigger":{"every":{"hour":4,"minute":5,"second":0},"type":"calendar"},"actions":[],"attachments":[],"autoClear":true,"defaults":0,"foreground":false,"groupSummary":false,"launch":true,"led":true,"lockscreen":true,"number":0,"priority":0,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"showWhen":true,"silent":false,"smallIcon":"res:\/\/icon","sound":true,"text":"","vibrate":false,"wakeup":true,"meta":{"plugin":"cordova-plugin-local-notifications","version":"0.9-beta"}},{"event":"trigger","foreground":true,"queued":false,"notification":1}))
12-14 04:06:04.024 30007-30007/io.ionic.starter D/CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.core.fireEvent("trigger",{"id":1,"title":"test title","trigger":{"every":{"hour":4,"minute":5,"second":0},"type":"calendar"},"actions":[],"attachments":[],"autoClear":true,"defaults":0,"foreground":false,"groupSummary":false,"launch":true,"led":true,"lockscreen":true,"number":0,"priority":0,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"showWhen":true,"silent":false,"smallIcon":"res:\/\/icon","sound":true,"text":"","vibrate":false,"wakeup":true,"meta":{"plugin":"cordova-plugin-local-notifications","version":"0.9-beta"}},{"event":"trigger","foreground":true,"queued":false,"notification":1}))
12-14 04:06:04.025 30007-30007/io.ionic.starter D/CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.core.fireEvent("trigger",{"id":1,"title":"test title","trigger":{"every":{"hour":4,"minute":5,"second":0},"type":"calendar"},"actions":[],"attachments":[],"autoClear":true,"defaults":0,"foreground":false,"groupSummary":false,"launch":true,"led":true,"lockscreen":true,"number":0,"priority":0,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"showWhen":true,"silent":false,"smallIcon":"res:\/\/icon","sound":true,"text":"","vibrate":false,"wakeup":true,"meta":{"plugin":"cordova-plugin-local-notifications","version":"0.9-beta"}},{"event":"trigger","foreground":true,"queued":false,"notification":1}))
12-14 04:06:04.026 30007-30007/io.ionic.starter D/CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.core.fireEvent("trigger",{"id":1,"title":"test title","trigger":{"every":{"hour":4,"minute":5,"second":0},"type":"calendar"},"actions":[],"attachments":[],"autoClear":true,"defaults":0,"foreground":false,"groupSummary":false,"launch":true,"led":true,"lockscreen":true,"number":0,"priority":0,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"showWhen":true,"silent":false,"smallIcon":"res:\/\/icon","sound":true,"text":"","vibrate":false,"wakeup":true,"meta":{"plugin":"cordova-plugin-local-notifications","version":"0.9-beta"}},{"event":"trigger","foreground":true,"queued":false,"notification":1}))
```
A lot of them
It happen when I use every property even like this
cordova.plugins.notification.local.schedule({
id: 10000,
title: 'test title',
trigger: {every: 'minute', firstAt: new Date(2017, 11, 15, 17, 12)}
});
Same issue here.
Ionic Framework: 3.9.2
Cordova version: 7.1.0
Cordova Android version: android 6.3.0
Device: Samsung Galaxy S7 (SM-G930F)
Android Version: 7.0
Plugin version: v0.9.0-beta.2
The point Repeating
in the README.md
says:
Or trigger every time the date matches
So it means every time the date matches. If I set the hour
to 10
and minute
to 30
, it will repeat the notification a minute long, until the date changed to hour
10
and minute
31
.
This ends up in spamming / flooding notifications, until the matched time ends up. Even if I set the second
to 0
, it spams / floods notifications, until the minute ends up.
If any further information is required, please let me know.
Cheers
Unkn0wn0x
Additional Informations from a Firebase Crash Reporting (thanks to Firebase), because the app doesn't responded anymore / crashed.
API-Level: 24
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer at de.appplant.cordova.plugin.notification.Request.getMatchingComponents(Request.java:219)
Exception java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
de.appplant.cordova.plugin.notification.Request.getMatchingComponents (Request.java:219)
de.appplant.cordova.plugin.notification.Request.buildTrigger (Request.java:158)
de.appplant.cordova.plugin.notification.Request.<init> (Request.java:75)
de.appplant.cordova.plugin.localnotification.LocalNotification.schedule (LocalNotification.java:270)
de.appplant.cordova.plugin.localnotification.LocalNotification.access$400 (LocalNotification.java:60)
de.appplant.cordova.plugin.localnotification.LocalNotification$1.run (LocalNotification.java:145)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1133)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:607)
java.lang.Thread.run (Thread.java:762)
Issue type, rated by Firebase is fatal.
@haha8x I tried with your code and it works as expected (tested with 0.9-beta.2)
@Unkn0wn0x
Please provide a sample code which reproduces the crash/behavor.
@katzer
My fault, sorry, here You go:
/** create a new array, which will hold all notification configurations */
let notifications: Array<any> = new Array();
/** create a single notification configuration */
const notificationConfig: Object = {
id: 1,
title: 'my title',
text: 'my message',
foreground: true
trigger: {
every: {
weekday: 1,
hour: 10,
minute: 30,
second: 0
}
}
};
/** push the single notification configuration into the notifications array */
notificationConfig.push(notificationConfig):
/** schedule the notifications array */
this.notificationCtrl.schedule(notifications);
If I open the console on my hybrid app and run the function
cordova.plugins.notification.local.getScheduled(function(data) {
console.log(data);
});
The newly created and scheduled notification appears as expected.
Here are some more details from the firebase crash report. As I expect, You are german, I hope it's okay, if the screenshot is in german.
Greetings from Munich :wave:
@haha8x
I tried out the code without being able to reproduce that bug. It worked well... Are you interfacing with the plugin in direct way or through some (Ionic native) wrapper?
To be able to get the same error message I need to assign a string instead of an integer. But thats not the plugins fault.
const notificationConfig: Object = {
id: 1,
title: 'my title',
text: 'my message',
foreground: true,
trigger: {
every: {
weekday: 1,
hour: 10,
minute: "30" // <- Would throw a ClassCastException
}
}
};
@katzer
I think You mean me instead of haha8x, or?
You're right. I'm using the ionic native wrapper:
Yep, I've noticed already, that a string would throw a ClassCastExpection.
I think, I found the "problem" in the ionic native wrapper. Take a look at the following line:
The ionic native wrapper expects a string for every
, but I'm passing an object into it.
Also I found some bugs in the ionic native repository, related to Your plugin:
especially this bug:
where it seems like the user has the same behaviour.
So I think it would be the correct way to use Your plugin without the ionic native wrapper.
I'll let You know today evening, if it worked or not.
Cheers
Unkn0wn0x
Hi, I have the same issue on Android. Works perfectly on iOS.
Scheduling works and is repeated every match, but the notification is triggered over and over again the whole minute.
I am using Ionic but use the plugin directly since Ionic still use an old version of the plugin..
Ionic: 3.19.1
Cordova: 7.1.0
Cordova Platforms: android 7.0.0
Cordova Android version: android 6.3.0
Plugin version: v0.9.0-beta.2
cordova.plugins.notification.local.schedule({
id: 1,
title: 'Hello',
text: 'World',
trigger: {
every: {
weekday: 1,
hour: 10,
minute: 30
}
},
})
@katzer
I can reproduce the same behaviour as @stinaa described.
chrome://inspect
cordova.plugins.notification.local.schedule({
id: 100,
title: 'my title',
text: 'my message',
foreground: true,
trigger: {
every: {
weekday: 2,
hour: 20,
minute: 45,
second: 0
}
}
});
I tried to listen on the triggered
event, but the WebView instantly stops to respond, after the first notification was pushed.
cordova.plugins.notification.local.on('trigger', function(data) {
console.log('triggered', data);
});
It fires notifications until the app does not respond anymore and then finally crashes. Even if the app was killed, it fires the scheduled notifications further on.
Cheers
Unkn0wn0x
--- edit ---
Okay, I've noticed another really curious behaviour.
If I set the trigger to early from the point, where I schedule the notification, it fires the notification the whole time. Tested with ~ one (1) minute.
On the other hand, if I let a little "delay" between the schedule and the trigger-time, tested with two (2) minutes, it works like a charm.
@katzer Do You have an explanation for that? :thinking:
Now I could reproduce. It happens when the components matches __now__ and no count
is specified.
Should be fixed now. Please reopen otherwise. You can use the master branch version or set count:
as a workaround.
There's no second
property for every
- It has always a zero value.
@katzer Tested with Your latest fix, works like a charm.
I really appreciate Your fast reply and hard work on this plugin!
Cheers
Unkn0wn0x
Hey @katzer, thanks for your quick reply and fix!
I tried to add count
and it works perfectly if I schedule the notification to trigger immediately (only trigger once), but if I want it to trigger in a few minutes, it doesn't work. Tried with 2 minutes and 5 minutes. Still working on iOS though.
Tried both with v 0.9.0-beta.2 and with latest version (commit 63c99d3ea1eb9a902fb9f1d121bdd99a243a45eb)
Example:
cordova.plugins.notification.local.schedule({
id: 100,
foreground: true,
title: 'my title',
text: 'my text',
trigger: {
count: 1,
every: { weekday: 4, hour: 10, minute: 28 }
}
})
This would work if I make the scheduling at Thursday 10.28, will trigger immediately. But if I schedule it at Thursday 10.27 (for 10.28), it is not triggered.
Wooooh . Same issue .
every: { weekday: 1, hour: 22, minute: 12 }
this floods my device with notifications !
p.s : at
and firstAt
is not specified
@xProgrammer-007 I tried yours using master without any flood. It calculates correct trigger dates. Also if the relative date points no _now_ which was the reason for the "flood" before.
@stinaa I adapter your code to point to a minute ahead from now but cannot reproduce any issue. The correct date is calculated and the notification is triggered as expected.
You need to use 0.9-beta.3 or at least these commit.
Just use :
trigger: { every: { hour: 20, minute: 20, second: 15 }, count: 1 },
it will be fired only once at the right time.
Hope it works 4 u too!
I came across this issue today on an HTC M9 running Android 7.0 with .
While adding count will stop the spamming it does not allow the notification to have any repeats (using every doesn't work when you add count).
an example where adding count fails to solve the problem:
cordova.plugins.notification.local.schedule({
title: 'message',
trigger: {firstAt: time2, every: "minute", count:1},
foreground: true,
id: 2
});
In this case the notification is only fired once and then notifications don't get repeated every minute afterwards.
I would suggest reopening this issue because:
the "just add count" workaround is not a slution to this problem -> it dosen't work in all uses cases.
Commit b93cf65 which is marked as the fix for this issue dose not solve this issue either.
I have the the same issue with @JoueBien . Is there any solution to this ?
@JoueBien and @mschristo , I was having the same problem here, so I changed "count" for 30, the multiple notifications didn't happen and it repeated for the next 2 days (Didn't test more). Probably will repeat for the next 30 days. One trick could be rescheduling the notification every time the user opens the app. Actually this is a nice feature to not repeat infinitely if the app is not being used. 馃棥
Same issue here every: { hour: 16, minute: 11}
notification comes multiples times at 16.11
I have another confirmed case of this.
The ionic wrapper (@ionic-native/local-notifications v4.17.0
) is not compatible with the latest versions of this plugin (beta 2 or beta 3). As a result, we are using the cordova plugin directly.
When using the cordova plugin directly:
every: { minute: 55 }
will fire notifications indefinitely while the clock reads "xx:55"count: 1
will only fire 1 notification, but it prevents the recurrenceIf we come up with a solution, I will be sure to update this post. It is maddening how fragile this ionic/cordova universe is.
Edit:
The unfortunate solution we came up with was reverting the ionic plugin AND this plugin back to old versions. We can now use the ionic plugin, and the notifications are recurring as expected.
"@ionic-native/local-notifications": "4.6"
"de.appplant.cordova.plugin.local-notification": "^0.8.5"
The unfortunate solution we came up with was reverting the ionic plugin AND this plugin back to old versions. We can now use the ionic plugin, and the notifications are recurring as expected.
"@ionic-native/local-notifications": "4.6"
"de.appplant.cordova.plugin.local-notification": "^0.8.5"
I revert my dependencies to those versions but... Fuc*sh :(
WORK
let options = {
id: this.idGenerator.generate(),
text: this.timeToMeditateNotificationText,
sound: this.notifySoundPath,
at: pickedDate,
every: 'minute'
};
this.localNotifications.schedule(options)
NO WORK T_T
let options = {
id: this.idGenerator.generate(),
text: this.timeToMeditateNotificationText,
sound: this.notifySoundPath,
at: pickedDate,
every: 'day'
};
this.localNotifications.schedule(options)
When every param has 'day' value doesn't work, but if I put 'minute' value works :|
@JoueBien and @mschristo , I was having the same problem here, so I changed "count" for 30, the multiple notifications didn't happen and it repeated for the next 2 days (Didn't test more). Probably will repeat for the next 30 days. One trick could be rescheduling the notification every time the user opens the app. Actually this is a nice feature to not repeat infinitely if the app is not being used. 馃棥
I had the same problem and that works for me. I use "count: 365"
Any update? I have the same issue. I need to notifiy every day at 08:00 AM and in Android it alert several times in the 08:00:XX minute.
this.localNotifications.schedule({
title: 'XXXXXXXXXXX',
text: 'YYYYYYYYYYYY',
icon: 'assets/img/icon.png',
vibrate: true,
trigger: { every: { hour: 8, minute: 0 }}
});
Like i need to be notified every day, i can't set the "count" atribute to 1.
Any workaround?
Thanks!
I believe this is still broken 3 years later. I changed companies since then and they don't use ionic, so I haven't bothered to follow up.
Considering that this package is so widely used by ionic projects you'd think someone would have fixed the issue by now.
Back when we ran into this issue we set up a week's worth of notifications every time the user opened the app.
I believe this is still broken 3 years later. I changed companies since then and they don't use ionic, so I haven't bothered to follow up.
Considering that this package is so widely used by ionic projects you'd think someone would have fixed the issue by now.
Back when we ran into this issue we set up a week's worth of notifications every time the user opened the app.
Thank for your comment. What you say, is to set the "count" atribute to 7 (in my case for 1 notification a day) no?.
I have a question about that. Now, when I start the app I schedule this notifications, and if I close de app, at 08:00 the notification is fired (well done). If I set a week's worth of notifications it could be that the notifications will be fired so many times as count*(number of app opened times)?
Thank you!
Any update? I have the same issue. I need to notifiy every day at 08:00 AM and in Android it alert several times in the 08:00:XX minute.
this.localNotifications.schedule({ title: 'XXXXXXXXXXX', text: 'YYYYYYYYYYYY', icon: 'assets/img/icon.png', vibrate: true, trigger: { every: { hour: 8, minute: 0 }} });
Like i need to be notified every day, i can't set the "count" atribute to 1.
Any workaround?
Thanks!
Try to use "count: 365" and execute "schedule()" each time the app is used. Only users who don't use the app during 1 year stop receiving notifications. This solves this issue (multiple notifications).
at 08:00 the notification is fired (well done). If I set a week's worth of notifications it could be that the notifications will be fired so many times as count*(number of app opened times)?
Thank you
We ditched the repeating and just set up a single non-repeating notification for the next seven days in advanced. Every time the user open the app we cleared the 7 notifications and re-set them for the next 7 days after the current day. This worked for us as the app was a spinal recovery app that the users were going to open every day.
@others adding count dose not work (it doesn't get used when every is present) when you have repeats so stop putting it forward as a solution - IT DOSE NOT WORK FOR THAT USE CASE.
Hi guys,
I will use the plugin to schedule weekly notification, so, I set to fire 999 weeks ( same as 19 years ).
count: 999
This was my work around.
Most helpful comment
Now I could reproduce. It happens when the components matches __now__ and no
count
is specified.