How to create a reminder with Expo-Notification that will be set to a specific date?

173 views Asked by At

I'm trying to set my notifications like this:

await Notifications.scheduleNotificationAsync({
    content: {
        title: "EnergieM - Pripomienka",
        body: "Spravte si novy odpocet",
        sound: "default",
    },
    trigger:{
        hour: 14,
        minute: 38,
        type: "weekly",
        weekday: 3,
    },
});

The result must be that the person chooses when to receive the notification (on a specific day every month or a specific day every week or every day)

enter image description here

But I'm always getting the same error: [Unhandled promise rejection: Error: Failed to get next trigger date for the trigger. Trigger of type: calendar is not supported on Android.]

Can someone please help me with these notifications? I am new to Expo and React-Native.

Would be grateful for any help!

1

There are 1 answers

1
elias00 On

Im not that good with using it either however I was able to get it to work. Dont know if its the best way or the intended way. But I did this.

    let currentDate = new Date()
    let eventDate = new Date(events[i].startDate)
    let diff = new Date(eventDate.getTime() - currentDate.getTime())
    let minutes = diff.getMinutes()
    let hours = diff.getHours()-1
    let days = diff.getUTCDate()-1
    let notificationTime = days * 86400 + hours * 3600 + minutes * 60

    Notifications.scheduleNotificationAsync({
      content:{
        title: "EnergieM - Pripomienka",
        body: "Spravte si novy odpocet",
        sound: "default",
      },
      identifier: events[i].id,
      trigger: {
        seconds: notificationTime,
        channelId:'default'
      }
    })

Basically I just calculate how long a day, hours etc is in seconds and call it by the total amount of seconds. You can easily calculate in how many days the notification is going to be called, and then just multiply the amount of days with 86400 to get the total amount of seconds untill then! If you want it reoccuring I do not know the answer. Hopefully this helps if not then I cant help you any further.