ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️
509 stars 577 forks source link

LocalNotifications: introduce `startTime` for `every` (intervals) #131

Open haschu opened 5 years ago

haschu commented 5 years ago

It would be nice if one could schedule an interval notification (e.g. every day) but with a custom startTime.

Consider the following example:

 notifications: [{
   // ....
   schedule: {
     every: 'day'
    }
   // ....
 }]

This schedules a notification that triggers every day from NOW on. So if one would schedule a notification at 11:00 am, it would trigger the next day at 11:00 am, and so on...

What I'm looking for is something like "remind every day on 08:00 am", so for example:

 notifications: [{
   // ....
   schedule: {
     every: 'day',
     startDate: aSpecificStartDate
    }
   // ....
 }]

This should be fairly easy to implement. Looking at the Android source, startTime needs to be configurable. (For the swift sources is's almost the same)

I would suggest to introduce a new property startTime for the schedule object. For me, this seems to be the most straightforward way, plus is stays backwards compatible.

Any thoughts on this? If you guys are okay with that solution I would give it a try and submit a pull request.

Or maybe am I missing something and there is a workaround for my problem?

DonWolfram commented 5 years ago

Hi, I got the same issue here. Daily reminders at a specific time would be awesome!

ralscha commented 5 years ago

Hi. You can already do that with on.

"remind every day on 08:00 am"

        schedule: {
          on: {
            hour: 8,
            minute: 0
          }
        }

"remind every day on 11:00 am"

        schedule: {
          on: {
            hour: 11,
            minute: 0
          }
        }

"remind every month on the 17th on 7:00 am"

        schedule: {
          on: {
            day: 17
            hour: 7,
            minute: 0
          }
        }
haschu commented 5 years ago

@ralscha Ah, thanks! Going to try that out :)

jansgescheit commented 5 years ago

I have a similar problem. The documentation is unfortunately insufficient. I would like to send notifications every Monday at 20:00, is that possible?

ralscha commented 5 years ago

@Jannnnnn Don't see a way to do that with the current implementation. A startTime for every would solve that. Or if on would support a day of week property, like cron.

jansgescheit commented 5 years ago

@ralscha I went through the source code and come to the same conclusion. I have now switched back to the cordova plugin https://github.com/katzer/cordova-plugin-local-notifications

askilondz commented 5 years ago

Looking for the ability to schedule a notification on a specific day of the week every week like @Jannnnnn mentioned. Any other thoughts on how to achieve this?

slevy85 commented 4 years ago

I think this an important feature for notifications, this issue is also the same as #2752

elnezah commented 3 years ago

@ralscha I went through the source code and come to the same conclusion. I have now switched back to the cordova plugin https://github.com/katzer/cordova-plugin-local-notifications

I have used this plugin for long. Is very buggy, not reliable, be careful and make a lot of test.

elnezah commented 3 years ago

I have the same problem as many here: want to place a weekly notification on a certain time of the day. Anybody knows what the parameter count is for? What happens if you combine every and on?

There is a huge lack of documentation here.

alphagamer7 commented 3 years ago

Bump

danielmalmros commented 3 years ago

+1 - I have been struggling with this issue for days. I can't find any relevant information on how to do this. I see a lot of different questions and issue about this, but no feedback from the core team?

the documentation says it's possible, but from what I can tell it dose not seem to be the case for daily or weekly reminders.

daveshirman commented 3 years ago

@mlynch @jcesarmobile

The documentation for this (V3) is extremely lacking. Please can someone update it to provide a way to:

  1. Schedule a DAILY notification at a specific time, e.g. Every DAY at 15:00
  2. Schedule a WEEKLY notification at a specific time, e.g. Every WEEK at 15:00
  3. Schedule a SPECIFIC DAY OF THE WEEK notification at a specific time, e.g. Every WEDNESDAY at 15:00

This is what we are trying to work out. The silence from the team is extremely frustrating. We want to use the Capacitor plugins, but if they aren't properly documented, how are we supposed to use and trust them over old Cordova ones?

Thanks.

daveshirman commented 3 years ago

+1 - I have been struggling with this issue for days. I can't find any relevant information on how to do this. I see a lot of different questions and issue about this, but no feedback from the core team?

the documentation says it's possible, but from what I can tell it dose not seem to be the case for daily or weekly reminders.

I've only tested this on Android (7, 9, 11) - but feel free to do what I did here, it's a workaround, but it works in my testing so far:

https://www.codingandclimbing.co.uk/blog/android-localnotifications-with-cordova-capacitor-example

danielmalmros commented 3 years ago

+1 - I have been struggling with this issue for days. I can't find any relevant information on how to do this. I see a lot of different questions and issue about this, but no feedback from the core team? the documentation says it's possible, but from what I can tell it dose not seem to be the case for daily or weekly reminders.

I've only tested this on Android (7, 9, 11) - but feel free to do what I did here, it's a workaround, but it works in my testing so far:

https://www.codingandclimbing.co.uk/blog/android-localnotifications-with-cordova-capacitor-example

@daveshirman amazing job with that blog post! Maybe just mention that it only seems to work with the 0.9.0-beta.3 cordova plugin. Looks like npm is installing the 0.9.0-beta.2 version. I'll do some more testing on both Android and iOS tomorrow to see if it helps with the daily reminders.

With that said, I still hope to see some clarification around the daily reminders from the Ionic team on the @capacitor/local-notifications plugin 🙏

daveshirman commented 3 years ago

+1 - I have been struggling with this issue for days. I can't find any relevant information on how to do this. I see a lot of different questions and issue about this, but no feedback from the core team? the documentation says it's possible, but from what I can tell it dose not seem to be the case for daily or weekly reminders.

I've only tested this on Android (7, 9, 11) - but feel free to do what I did here, it's a workaround, but it works in my testing so far: https://www.codingandclimbing.co.uk/blog/android-localnotifications-with-cordova-capacitor-example

@daveshirman amazing job with that blog post! Maybe just mention that it only seems to work with the 0.9.0-beta.3 cordova plugin. Looks like npm is installing the 0.9.0-beta.2 version. I'll do some more testing on both Android and iOS tomorrow to see if it helps with the daily reminders.

With that said, I still hope to see some clarification around the daily reminders from the Ionic team on the @capacitor/local-notifications plugin 🙏

Have updated my post to reference exact plugin url I used, hint it's not the katzer one that appears everywhere:

npm install https://github.com/Steffaan/cordova-plugin-local-notifications.git;

@danielmalmros

EDIT: The notification didn't trigger for the consecutive days, so I've updated my post with count in the trigger, i.e:

trigger: { every: { hour: hours, minute: mins }, count: 365 },

Manually changing the date + time seems to trigger it, but will do more testing letting the phone do its thing over the next few days.

Any other info your side?

digaus commented 3 years ago

Is it possible you look into this? I am fairly certain it would be easy on the android side at least.

Just make it possible to combine at with every or on.

The current interval for repeating notifications using at does not make any sense https://github.com/ionic-team/capacitor-plugins/blob/main/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java#L348

I would suggest to just use the at parameter as a startTime for the repeating alarm when every or on is set.

https://github.com/ionic-team/capacitor-plugins/blob/main/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java#L365 https://github.com/ionic-team/capacitor-plugins/blob/main/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java#L374

For iOS we would have to do something similar.

Any reason against this?

tomeberhard commented 2 years ago

bumping this up. As users of ionic, we would like to be able to setup a daily notification at a specific time. (and a weekly one on a specific day and specific time)

the source code https://github.com/ionic-team/capacitor-plugins/blob/main/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java#L340

does not seem to support that functionality.

If we use "every": day", we can't specify the start time. (kinda important, don't you think?) source code does this: long startTime = new Date().getTime() + everyInterval; should be long startTime = schedule.getAt() // but if there's an at specified, we don't get this far in the code.

if we use "on:" new Date(year, month, day, hour, minute, second) and "repeat", it repeats once a year. (or can we use count 365?)

The original poster covered it pretty clearly. We spent 2 days on this before digging into the source code.

galaxyblur commented 2 years ago

Would love to see this supported!

ionicsiva commented 1 year ago

bumping this up. As users of ionic, we would like to be able to setup a daily notification at a specific time. (and a weekly one on a specific day and specific time)

the source code https://github.com/ionic-team/capacitor-plugins/blob/main/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java#L340

does not seem to support that functionality.

If we use "every": day", we can't specify the start time. (kinda important, don't you think?) source code does this: long startTime = new Date().getTime() + everyInterval; should be long startTime = schedule.getAt() // but if there's an at specified, we don't get this far in the code.

if we use "on:" new Date(year, month, day, hour, minute, second) and "repeat", it repeats once a year. (or can we use count 365?)

The original poster covered it pretty clearly. We spent 2 days on this before digging into the source code.

I have the same issue as many others here: I want to build a daily notification on which time is selected in frontend and want to execute a daily notification at the same time every day. I tried the repeats: true and every: 'day' here, but it didn't work for me. I tried this and searched everywhere.

I'm Using Ionic with angular on that am Using the Local Notification capacitor plugin.

Look for my code below.

import { LocalNotifications } from '@capacitor/local-notifications';

async setAlarm() { const now = new Date(); const alarmDate = new Date(this.alarmTime); const alarmTime = new Date(); alarmDate.setFullYear(now.getFullYear(), now.getMonth(), now.getDate());

if (alarmDate <= now) { alarmDate.setDate(alarmDate.getDate() + 1); }

await LocalNotifications.schedule({

notifications: [ { title: 'Alarm', body: 'Time to wake up!', id: 1, schedule: { at: new Date(this.alarmTime), repeats: true, every: 'day', }, actionTypeId: '', extra: null, }, ], });

alert('Alarm set for ' + alarmDate.toLocaleTimeString() + '.'); }

danielmalmros commented 1 year ago

@ionicsiva we had the exact same issue on our end. I really hope this is something the Capacitor team will prioritise.

After spending days trying to solve this and even play around with source code, we decided to go with a backend implementation and OneSignal for all of our notifications. But with that said, the local notification should something that is a core part of Capacitor.

jansgescheit commented 1 year ago

Daily Notifications should work. In my app the user can set a weekday and a time when notification should be sent, e.g.

import { LocalNotificationSchema, LocalNotifications, Weekday } from '@capacitor/local-notifications';

const notifyAt = new Date();
const notifications: LocalNotificationSchema = [
    Weekday.Monday,
    Weekday.Tuesday,
    Weekday.Wednesday,
    Weekday.Thursday,
    Weekday.Friday,
    Weekday.Saturday,
    Weekday.Sunday,
]
.map(weekday => {
    return {
        title: 'some title',
        body: 'some body',
        id: weekday,
        schedule: {
            on: {
                weekday,
                minute: notifyAt.getMinutes(),
                second: 0,
                hour: notifyAt.getHours(),
            },
        },
    };
});

await LocalNotifications.schedule({ notifications })
ionicsiva commented 1 year ago

Daily Notifications should work. In my app the user can set a weekday and a time when notification should be sent, e.g.

import { LocalNotificationSchema, LocalNotifications, Weekday } from '@capacitor/local-notifications';

const notifyAt = new Date();
const notifications: LocalNotificationSchema = [
    Weekday.Monday,
    Weekday.Tuesday,
    Weekday.Wednesday,
    Weekday.Thursday,
    Weekday.Friday,
    Weekday.Saturday,
    Weekday.Sunday,
]
.map(weekday => {
    return {
        title: 'some title',
        body: 'some body',
        id: weekday,
        schedule: {
            on: {
                weekday,
                minute: notifyAt.getMinutes(),
                second: 0,
                hour: notifyAt.getHours(),
            },
        },
    };
});

await LocalNotifications.schedule({ notifications })

Thank you for your assistance; it's working. Sending love from India!👍❤️

orjandh commented 3 months ago

I was very surprised this was not supported. After digging a little deeper it seems unfortunately to be a limitation in iOS, though it seems possible on android. Please correct me if I'm wrong.