ios icon indicating copy to clipboard operation
ios copied to clipboard

Notifications with fireDate after next day do not trigger

Open devinjameson opened this issue 5 years ago • 8 comments

When using addNotificationRequest, if the fireDate is not within the current day, the notification never triggers.

const [reminderTime, setReminderTime] = useState<Date>(new Date())

const request: NotificationRequest = {
  id: "id",
  title: "Friendly reminder:",
  body: "body",
  fireDate: reminderTime,
  repeats: true,
}
Notifications.scheduleNativeNotification(request)

const scheduleNativeNotification = async (
  request: NotificationRequest,
): Promise<void> => {
  const pushNotificationPermissions = await PushNotificationIOS.requestPermissions()
  if (pushNotificationPermissions.authorizationStatus === 2) {
    PushNotificationIOS.addNotificationRequest(request)
  }
}

devinjameson avatar Dec 08 '20 00:12 devinjameson

@johnschoeman see above for notification delivery issue.

devinjameson avatar Dec 08 '20 00:12 devinjameson

Any ideas on this? Additionally, if the fireDate is for the same day, the notification triggers once but does not repeat even if repeats is set to true.

devinjameson avatar Dec 14 '20 01:12 devinjameson

same issue :/

solo29 avatar Dec 25 '20 18:12 solo29

try using PushNotificationIOS.scheduleLocalNotification until its resolved

solo29 avatar Dec 25 '20 19:12 solo29

I wrote my own native module to get around this @solo29. You can find it here: https://github.com/johnschoeman/building-habits-rn/tree/master/src/notifications.

And the Swift implementation: https://github.com/johnschoeman/building-habits-rn/blob/master/ios/NotificationsManager.swift

devinjameson avatar Jan 05 '21 15:01 devinjameson

facing a similar issue where the notification is only triggered when addNotificationRequest is called without fireDate field in it. any Date mentioned the notification is not triggered.

i1990jain avatar Feb 08 '21 15:02 i1990jain

So I have just encountered this same issue. The other issue is that the notification never repeats on susbsequent days either. I am pretty sure I have found the cause. In RCTConvert+Notification.m there is logic that transforms the JSON config into Objective-C types. https://github.com/react-native-push-notification-ios/push-notification-ios/blob/9fa4ff7763c099ce04bd76f3cd2d7fdbd5e8ea13/ios/RCTConvert%2BNotification.m#L120-L125 To create the trigger for the notification it uses the UNCalendarNotificationTrigger class. If you read the documentation for this it's clear that the conversion used won't work. It sets the notification to run on a specific year + month + day + hour + minute + second. As such it will never run again. To make this run daily, the year, month, and day values need to be removed from the calendar definition. This is simmilar to cron logic in a way, except with this class you need to ommit a metric to make it a wild card. For instance if you wanted a notification to be sent at 8:30am on the 2nd of each month you would specify day = 2, hour = 8, minute = 30, and second = 0, but not the month or year.

I'm going to have a go at fixing this.

jamesxabregas avatar Jul 18 '21 12:07 jamesxabregas

any update?

YaoHuiJi avatar Aug 09 '21 07:08 YaoHuiJi