Hi,
I am scheduling multiple notifications, with a maximum of 24, and setting them to repeat daily. I am using the code below to trigger notifications and add them to a list. I verify the notifications using the getTriggerNotification() method.
const reminders = [
{ slotTime: 0, time: '12 AM' },
{ slotTime: 360, time: '06 AM' },
{ slotTime: 720, time: '12 PM' },
{ slotTime: 1080, time: '06 PM' },
// Add more reminders up to 24
];
export const setupRepeatIPDReminders = async () => {
// Get Filter slot data for reminder update
const reminders = getUniqueSlotForReminder()
console.log('SetupRepeatIPDReminders Reminder =--->', reminders)
await notifee.requestPermission()
// Remove all old Trigger Notification
await removeAllReminder()
// Create channel
const channelId = await notifee.createChannel({
id: 'reminder-ipd-channel',
name: 'ic_notification',
})
try {
await Promise.all(
reminders.map((reminder: any) => {
const { slotTime, time } = reminder
const now = moment()
const nextOccurrence = moment()
.startOf('day')
.add(slotTime * 60 * 1000, 'milliseconds')
if (nextOccurrence.isBefore(now)) {
nextOccurrence.add(1, 'day') // if the next occurrence is in the past, add 1 day
}
const timestamp = nextOccurrence.valueOf()
// const timestamp = new Date().getTime() + 10 * 60 * 1000 // This line use for testing
const notificationObj = {
id: `ipd-${slotTime}`,
title: 'IPD sheet update reminder',
body: `Reminder at ${time}`,
android: {
channelId,
},
ios: {
sound: 'default',
},
}
const triggerObj: TimestampTrigger = {
repeatFrequency: RepeatFrequency.DAILY,
timestamp,
type: TriggerType.TIMESTAMP,
}
return notifee.createTriggerNotification(notificationObj, triggerObj)
}),
)
} catch (error) {
console.log('Error notification configure exception =------->', error)
}
const notification = await notifee.getTriggerNotifications()
console.log('Notification =----->', notification)
}
Could you please help me improve this process?
Thank you!
Hi,
I am scheduling multiple notifications, with a maximum of 24, and setting them to repeat daily. I am using the code below to trigger notifications and add them to a list. I verify the notifications using the getTriggerNotification() method.
Could you please help me improve this process?
Thank you!