react-native-calendar-events
react-native-calendar-events copied to clipboard
The alarm is not working
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.
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' }] })
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(),
}
]
Can someone pls add this in the description, it would be very helpful! (I have also run in this issue! )
Thanks, Dude
This also works: date: Platform.OS === 'ios' ? -60 : 60
(60 minutes before the event)
Thanks @geastwood and @janziemba ! It would be nice to add this soon to the example documentation.