react-native-calendar-events icon indicating copy to clipboard operation
react-native-calendar-events copied to clipboard

The alarm is not working

Open LongicornYu opened this issue 6 years ago • 6 comments

I tried to add an calendar event with alarm: RNCalendarEvents.saveEvent(Alert for taking pills, { notes: data[1], description: data[2], startDate: start, endDate: end, recurrence: 'daily', calendar: ['Calendar'], alarm: [{ date: -1 }], }) .then(id => { // we can get the event ID here if we need it }).catch(error => console.log('Save Event Error: ', error));

Then in the system calendar, I can see the event is created, however, the alert is none. Also there is no notification/alert one minus before the event starts. Am I doing something wrong in creating the event? Thanks.

LongicornYu avatar Jun 08 '18 02:06 LongicornYu

I also tired but it is fail. RNCalendarEvents.saveEvent('Title of event', { startDate: '2018-06-21T19:21:00.000Z', endDate: '2018-06-21T19:21:00.000Z', alarms: [{ date: '2018-06-22T19:21:00.000Z' }] })

ycman0307 avatar Jun 22 '18 07:06 ycman0307

From what I see from the source code, on iOS the date needs to be iso string, however on Android, the date needs to be number (which is used as minutes, e.g. given date: 2, in Android it will convert to 2 minutes before)

It's better to do a branching on Platform, e.g.

[
        {
            date:
                Platform.OS === 'ios'
                    ? moment(startsOnDate)
                          .subtract(2, 'hours')
                          .toISOString()
                    : moment.duration(2, 'hours').asMinutes(),
        }
]

geastwood avatar Jul 19 '18 09:07 geastwood

Can someone pls add this in the description, it would be very helpful! (I have also run in this issue! )

apppro123 avatar Apr 28 '19 14:04 apppro123

Thanks, Dude

gilons avatar Dec 08 '19 01:12 gilons

This also works: date: Platform.OS === 'ios' ? -60 : 60 (60 minutes before the event)

janziemba avatar Feb 27 '20 08:02 janziemba

Thanks @geastwood and @janziemba ! It would be nice to add this soon to the example documentation.

GustavoBonfimS avatar Dec 10 '21 14:12 GustavoBonfimS