0

In documentation I cannot see how I can choose a specific date, even though its mentioned its possible. All I see is:

async function schedulePushNotification() {
  await Notifications.scheduleNotificationAsync({
    content: {
      title: "You've got mail! ",
      body: 'Here is the notification body',
      data: { data: 'goes here' },
    },
    trigger: { seconds: 2 },
  });
}

that would send a notification every *(in this case 2 seconds)

i can also do:

trigger: {
minute: 16,
second: 12
}

that would send the notification at 4 pm and 12 seconds. but I cannot see how I can choose the day. I could calculate a month in seconds and pass it to seconds, but thats not very reliable and also would as I understand be repeating which i dont want. How do I do it? I just want to send a reminder notification to users who havent been in the app for lets say 2 month so every time a user logs in a schedule a notification from Date.now plus 2 months

1 Answers1

0

This should work, the +60 is an hour in the future

import * as Notifications from 'expo-notifications';

const trigger = new Date(Date.now() + 60 * 60 * 1000);
trigger.setMinutes(0);
trigger.setSeconds(0);

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