This is one tricky bug. Some context: I have a time picker shown to user that allows them to choose their notification time. I then take that time and feed it as 'fireDate' to addNotificationRequest. Expected behaviour is that it triggers the notification on that time, but here is what happens:
It doesn't trigger the notification if it is the first launch of the app. But it works if I close and reopen the app.
It works on first launch if I don't set a fireDate, and it triggers the notification immediately.
It works on first launch if set fireDate as new Date(Date.now() + 1000 * 60). This triggers the notification in 1 minute as expected.
The date object from the time picker is the literal same as Date.now() + 1 minute, and yet the latter works but not the former.
Do note that even in the latter case, I still open the time picker to eliminate any issues with the time picker.
I'm completely stumped, there are two issues similar to this:
This comment is similar in that it works with no fireDate but not with custom time
This issue but again it's different because the notifications work on first launch if I don't set a fireDate or if I set Date.now() + 1 minute
This is my code:
/**
* @description function to start notification service
* @param time
*/
export const startNotificationOnTime = async (
time: Date,
removeOld: boolean = true
): Promise<void> => {
await PushNotificationIOS.requestPermissions();
PushNotificationIOS.addNotificationRequest({
body: stringConstants.notifications[1].body,
title: stringConstants.notifications[1].title,
fireDate: time,
repeats: true,
isSilent: true,
id: "0",
});
};
This is one tricky bug. Some context: I have a time picker shown to user that allows them to choose their notification time. I then take that time and feed it as 'fireDate' to addNotificationRequest. Expected behaviour is that it triggers the notification on that time, but here is what happens:
new Date(Date.now() + 1000 * 60)
. This triggers the notification in 1 minute as expected.The date object from the time picker is the literal same as Date.now() + 1 minute, and yet the latter works but not the former.
Do note that even in the latter case, I still open the time picker to eliminate any issues with the time picker.
I'm completely stumped, there are two issues similar to this:
This is my code: