react-native-push-notification / ios

React Native Push Notification API for iOS.
MIT License
740 stars 284 forks source link

Really strange bug with addNotificationRequest #274

Open isonlaxman opened 3 years ago

isonlaxman commented 3 years ago

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:

  1. 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.
  2. It works on first launch if I don't set a fireDate, and it triggers the notification immediately.
  3. 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:

  1. This comment is similar in that it works with no fireDate but not with custom time
  2. 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",
  });
};
devinjameson commented 3 years ago

This might be helpful: https://github.com/react-native-push-notification-ios/push-notification-ios/issues/247

bilalattari commented 2 years ago

Any solution for this??