2

The challenge is: how can I set up the start date for notification in the new expo API. In the old API (which is depricated today) it was feasible but I can't see the solution in the new doc

For example: set up a notification on every 2nd day start from a user given date (e.g. 12th of Jan).

I went through on these types

export type SchedulableNotificationTriggerInput =
  | DateTriggerInput
  | TimeIntervalTriggerInput
  | DailyTriggerInput
  | WeeklyTriggerInput
  | CalendarTriggerInput;

but no success so far.

  • Is there a reason you can't use the `trigger` like in the example in the docs? https://docs.expo.io/versions/latest/sdk/notifications/#examples-9 – p-syche Jan 13 '21 at 12:38
  • my problem is the "start date". in the new API (the example you sent) on the `trigger` there is no start date anymore just seconds and repeat true/false. – Gabor Czene Jan 13 '21 at 16:00

1 Answers1

0

As far as I can tell you should be able to set the start date this way:

const dateString = "21/01/2021"; // Jan 21

const trigger = new Date(dateString);
trigger.setMinutes(0);
trigger.setSeconds(0);

Notifications.scheduleNotificationAsync({
  content: {
    title: 'Happy new hour!',
  },
  trigger,
});

You should play around with trigger.setMinutes and trigger.setSeconds to set a specific hour on your specific day.

p-syche
  • 575
  • 1
  • 5
  • 17