Cordova-plugin-local-notifications: Scheduling notifications with repeat is triggered at wrong date

Created on 5 Jan 2018  路  17Comments  路  Source: katzer/cordova-plugin-local-notifications

Im simply scheduling a notification. I use moment js to start the scheduling tomorrow at an hour specified by the user.

So i just simply: let date = moment(date).add(1, 'days').toDate() do this to get the next day.
Then i just
`

 //We set the new date to the next notifications
 let notification = { 
       title: "Welcome",
       text: "Lets start with your first reflection", 
       at: new Date(), 
       every: '"day"
 };
 notification.at = date;
 this.localNotifications.schedule(notification);

`

To be sure I print the notification.at, and I've got the tomorrow at some hour correctly. But the device don't care about the at. It just takes the hour. Example, if I right now are the 20:00, and I scheduled something for tomorrow at 20:02, the notification is fired in two minutes.

Your Environment

  • Plugin version: 0.8.5
  • Platform: iOS
  • OS version: 11.2
  • Device manufacturer / model: iPhone 7
  • Cordova version: 7.1.0
  • Cordova platform version: 7.1.0
  • Plugin config
  • Ionic Version (if using Ionic): 3.19.0

Expected Behavior

Lets suppose it's 22:00pm, and I schedule an hour introduced by the user (that hour will be 22:05pm) and do the next thing. let date = moment(date).add(1, 'days').toDate();
So the first notification must be triggered everyday starting tomorrow at 22:05.

Actual Behavior

Lets suppose it's 22:00pm, and I schedule an hour introduced by the user (that hour will be 22:05pm) and do the next thing. let date = moment(date).add(1, 'days').toDate();
So the first notification must be triggered everyday starting tomorrow at 22:05, but instead, the first notification it's triggered today at 22:05pm

Steps to Reproduce

  1. Create a date with the value of tomorrow, and with some minutes of difference with your actual hour.
  2. Schedule that date
  3. The notifications will start to be triggered today instead of tomorrow

Context

I'm trying to schedule repeating notifications everyday, starting from tomorrow.

Debug logs

_Include iOS / Android logs_

  • ios XCode logs
  • Android: $ adb logcat
bug ios

All 17 comments

You're firing the notification every day. I think you need to look at the startAt concept.

@JoshuaPerk I've tried with firstAt and it was the same. Also I read here https://github.com/katzer/cordova-plugin-local-notifications/issues/1412 that firstAt does not work and will not work on iOS

With iOS 10+ there's no support for firstAt property anymore, but instead there are other options with v0.9

@katzer So if I understand you correct with the firstAt value not supported on iOS. It is not possible to make a notification that is repeated every friday at for example 16:00, both on Android and iOS?

{ trigger: { every: { weekday: 5, hour: 16, minute: 0 } } }

Nice! Thank you @katzer ! 馃槃

@katzer Just one question! Is weekday not supported in the current version 0.8.5? Seems that the hour and minute values works great, but not with the weekday value.

The whole syntax and feature-set (not just weekday) requires v0.9

With v0.8 you would need to calculate the first date and specify a weekly interval.

Ok, but is the v0.9 available at any branches? My config.xml file includes this plugin line:
plugin name="cordova-plugin-local-notification" spec="git+https://github.com/katzer/cordova-plugin-local-notifications.git
But should i add a specific branch for the syntax to be working?

... is the v0.9 available at any branches?

master branch

Ah ok, my bad. So the plugin line in the config.xml is know looking like this:
plugin name="cordova-plugin-local-notification" spec="^0.9.0-beta.1"
Is that correct?

Should the cordova version be 7.1.0 or 8.0.0 ?

with 8.0.0 I had to remove an .xml file manually. Other then it works with both 7.1 and 8.0

Nice, I am using the version 7.1.0 so i think i would use that one for now. Here is my function for the notification that is been added to a array of notifications to be scheduled:

let notification = {
id: 1,
title: 'Example title',
text: 'Example text',
trigger: { every: { weekday: 3, hour: 8, minute: 59 } },
foreground: true,
actions: [
{ id: 'yes', title: 'Yes' },
{ id: 'no', title: 'No' }
]
}

The trigger is set to current time for testing out that it works. The notification works when I don't use the weekday value, but maybe i don't have the syntax right?

support for weekday for Android+Windows has been added after the release of 0.9.beta.1

Ok, I am testing this on iOS in the emulator on macOS. And it still dont work. Another value like weekOfMonth work fine.

Has been fixed!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jomarocas picture jomarocas  路  3Comments

Shashank2406 picture Shashank2406  路  5Comments

Kasendwa picture Kasendwa  路  3Comments

ibnbd picture ibnbd  路  4Comments

bhumin3i picture bhumin3i  路  5Comments