ios
ios copied to clipboard
Really strange bug with addNotificationRequest
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 might be helpful: https://github.com/react-native-push-notification-ios/push-notification-ios/issues/247
Any solution for this??