Closed alesgenova closed 1 week ago
Btw, I'm probably gonna use this workaround in the meantime, since it seems to be working somewhat ok.
setNotifications(every: string, firstAt: Date){
let notifications = [];
let n:number = 63; // arbitrary large number
let title: string = "Title";
let text: string = "Text";
for (let i=0; i<n; i++){
let theAt = new Date(firstAt);
if (every == 'minute'){
theAt.setMinutes(theAt.getMinutes()+i);
}else if (every == 'hour'){
theAt.setHours(theAt.getHours()+i);
}else if (every == 'day'){
theAt.setDate(theAt.getDate()+i);
}else if (every == 'week'){
theAt.setDate(theAt.getDate()+i*7);
}
notifications.push(
{
id: i,
title: title,
text: text,
icon: "",
sound: true,
smallIcon: "res://"+this.notificationStrings.icon,
//foreground: true,
wakeup: false,
trigger:{
at: theAt
}
}
);
}
cordova.plugins.notification.local.schedule(notifications,()=>{
console.log("notification set ", firstAt, every);
});
}
Every time the app is started, I cancelAll() and then reset a new set of notifications, making sure that firstAt is at the appropriate time in the future.
Nevermind, it looks like my install script reverted automatically to 0.9.0-beta2 when installing the plugin using @latest . 0.9.0-beta3 doesn't show the repetition behavior.
However, I will stick to using my workaround, because it should work on iOS too where firstAt is not available, and it also restores the notifications after a reboot on android if foreground: true and priority: 1 is set.
Thanks for the plugin!
Actually, I tried again today, and the problem seems to be there on beta3 as well. Reopening the issue
@alesgenova Please make sure again that you're running beta.3 and provide a working sample. In case of date issues its important to know how the start date and the trigger date correspond together. For example the endless loop happens by setting trigger.at to now.
Yes this time I'm sure I'm running beta.3
The code to reproduce it it's the following.
What I expect: I expect a notification to be fired every hour at :00 minutes. What happens: At the expected time, infinite notifications get triggered (like 2 or more per second), and they keep on firing until the clock turns to :01
let notifications = [
{
id: 0,
title: "title",
text: "text",
icon: "",
smallIcon: "res://"+this.notificationStrings.icon,
wakeup: false,
foreground: true,
priority: 1,
trigger: {
every: {minute: 0},
}
}
]
cordova.plugins.notification.local.schedule(notifications,()=>{
console.log("notification set ");
});
@alesgenova Yes thats a bug in the code for Android and Windows if the minute is lower compared to the base date. However there's no infinite loop. The plugin wont schedule any notification because the calculated date is in the past.
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 am getting this error message, This is my code
this.localNotifications.schedule({
id:1,
title:"Reminder",
text:"Please drink water",
priority:2,
trigger:{ every:{minute:30}}
})
trigger: { every: { minute: number; ...' is not assignable to parameter of type 'ILocalNotification | ILocalNotification[]'
I want to get a notification on every 30 minutes.
To avoid the repeated notifications every second, set "count" to some large number.
cordova.plugins.notification.local.schedule({
id: 0,
title: title,
text: text,
trigger: {
firstAt: at,
every: 'minute',
count: 1440,
},
});
This seems to work:
import {LocalNotifications, ELocalNotificationTriggerUnit} from '@ionic-native/local-notifications';
` let date = new Date(new Date().getTime() + 3600);
this.localNotifications.schedule({ text: 'Local notification', trigger: { firstAt: date, every: ELocalNotificationTriggerUnit.MINUTE, count: 5, }, });`
@katzer firstAt is not working on iOS, so how on earth is it possible to trigger a notification on a specific time and then let it trigger every minute from that time unless it's cancelled.
Not working:
this.localNotifications.schedule({ id, text: title, trigger: { at: when.toDate() }, every: "minute", });
Not working:
this.localNotifications.schedule({ id, text: title, trigger: { at: when.toDate(), every: { minute: 0 }, }, });
Not working:
this.localNotifications.schedule({ id, text: title, trigger: { at: when.toDate(), every: ELocalNotificationTriggerUnit.MINUTE }, });
This works, but then it doesn't fire every minute... When using 'at' and 'every' together, the notification does not get scheduled at all.
this.localNotifications.schedule({ id, text: title, trigger: { at: when.toDate() }, });
Hello everybody!
I had this problem for a long time and I just found out that the master branch has already resolved this issue. All this time I installed it through package.json so I was using the "0.9.0-beta.3" and "0.9.0-beta.2"
So if you use the repository url in the config.xml file, it will work. Or you can fork the project and make your own release.
@katzer can you please make a release with your latest commits.
Thank you in advance.
@marioshtika I have the same issue. Are you saying that in 0.9.0-beta.3 this issue does not exist and npm version is 0.9.0-beta.2?
Hello @stefaneli31, watch the below timeline to understand what I am saying.
11 Jan 2018: 0ac0372 - Release v0.9.0-beta.2 (Issue exists) 13 Jan 2018: a75c097 - Release 0.9-beta.3 (Issue exists) 21 Feb 2018: b93cf65 - Fix bug in match trigger where interval is every minute (Issue fixed) . . . 7 Feb 2019: 06baff7 - Fix wrong prio constants (latest commit with a lot of other bug fixed)
Right now the npm version is 0.9.0-beta.2. But in both '0.9.0-beta.2' and '0.9.0-beta.3' this issue still exists. Only if you download the master branch you will not have this problem.
Or the best solution would be if @katzer could make a new release with all the new commits.
@marioshtika Hi, thank you for the explanation. It works. :) Also just to point out you can download the master branch by specifying the branch after hashtag - like this: spec="https://github.com/katzer/cordova-plugin-local-notifications.git#master"
@stefaneli31
You are right. I think it also needs the 'ANDROID_SUPPORT_V4_VERSION'
on config.xml
<plugin name="cordova-plugin-local-notification" spec="https://github.com/katzer/cordova-plugin-local-notifications.git#master">
<variable name="ANDROID_SUPPORT_V4_VERSION" value="26.+" />
</plugin>
@stefaneli31 I am using this version , but the plugin only trigger the last notifications l scheduled . ??
@MoradAbdelgaber do you have a different id
for each notification?
example:
cordova.plugins.notification.local.schedule([
{ id: 1, title: 'My first notification' },
{ id: 2, title: 'Another notification' }
]);
@marioshtika. Yes I provide differrent Id , I am using Math.random() functionality to handle this . Any idea to solve this ?
Do you mean Math.random() functionality? Can you provide some code sample?
@marioshtika Let rand = Math.random(); Cordova.plugins.notification.local.schedule({ id : rand , title : 'title' , text : 'text', foreground : true , trigger : { every : { weekday : 1 , hour : 9 , minute : 0
} } })
I think the Math.random()
gives you a random number from 0 to 1.
Another approach is the below
lastNotificationId: number;
constructor() {
this.localNotifications.getIds()
.then((ids: number[]) => {
this.lastNotificationId = ids.length > 0 ? Math.max(...ids) : 0;
})
}
schedule() {
this.lastNotificationId++;
Cordova.plugins.notification.local.schedule({
id: this.lastNotificationId,
.
.
.
});
}
console.log
your notification for debugging and see what id
did you use.
I have solved the problem . The problem was the plugin see all the ids is the same if it is not equal mathematically. I have changed the id from Math.random() to new Date().getTime().
i installed the latest head version, works fine right now. cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications.git
@codeboros @marioshtika is the plugin working fine ? I am still facing the issue when i try to trigger the notification for every week in android 9. Can you please help me in solving this? Which is the stable version i need to install ?
@Kudla161992 are you still having problem with the countless notifications?
the solution is adding the plugin using its repository url:
cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications.git#master
make sure you remove any previous version of this plugin before adding the new one.
check if the plugin exists with:
cordova plugin list
and remove previous version with:
cordova plugin add cordova-plugin-local-notifications
@marioshtika I followed the same steps as per your comment. Now the problem of countless trigger is solved but unfortunately , the notification doesn't trigger for the next scheduled time. Suppose I schedule the notification for all the days of the week, it triggers only once for today and no notifications are triggered for the other scheduled days.
Package.json: "cordova-plugin-local-notification": "git+https://github.com/katzer/cordova-plugin-local- notifications.git#master" "cordova-plugin-local-notification": { "ANDROID_SUPPORT_V4_VERSION": "26.+" }
Code:
this.localNotifications.schedule({
id:id,
title: title,
text: 'My Notification',
trigger: { every : { weekday: Date.getDay(), hour:Date.getHours() ,
minute:Date.getMinutes() }},
sound: 'res://platform_default',
data: {
day: reminderItem.day
}
});
Please check the trigger part of the code. Not sure if i am doing something wrong here.
I want the notification to trigger everyday(or the day selected by the user )on the scheduled time.
Hello @Kudla161992. How are you testing it. I think the above code is triggered every week not every day. Example
every : {
weekday: 1,
hour: 10,
minute:0
}
This will notify you every Monday at 10 o'clock
Try testing it by scheduling every minute, just to test if it is working.
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!
@renato-rodrigues-t1 Is it fired every day at mentioned time ( { hour: 20, minute: 20, second: 15 }) ???
Hi , I have recently downloaded the plugin using
cordova plugin add cordova-plugin-local-notification
and facing the same error of the app becoming unresponsive for the time of 1 minute in which notification was scheduled using early.
I used count : 1 but when I used that notification was shown for only once and with no repeat for consecutive days.
this.localNotifications.schedule( { id : new Date().getTime(), title: this.name + " Hello", text: ''Please guide", trigger: { every : { hour : Number(hours),minute : Number(minutes) } , count : 1 }, } );
Is this the same issue that is dealt with here https://stackoverflow.com/questions/55379397/local-notification-trigger-continuously-for-one-minute-in-android-device/56747645#56747645 ? (That fix to the java file fixed the repeating notification on android for our project)
WARNING: IF YOU IGNORE THIS TEMPLATE, WE'LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!
Provide a general summary of the issue.
Your Environment
cordova -v
): 8.0.0cordova platform ls
): android 6.4.0Expected Behavior
There should be a single notification at the specified time, and the nothing until the following minute/hour/day/week
Actual Behavior
I'm trying to get a daily/weekly notification, but I ran into a bug. When the matching time comes, notifications start firing (i.e. more than one notification per second), until the clock of the phone changes. I fround this issue both using the every match, and every repeat
Steps to Reproduce
Context
Debug logs
Continues like this for several MB