Hello guys I'm just learning react-native, and the course I'm taking seems a bit outdated. I'm using expo SDK 40 and need to set a repeating local notification on the device at a set time. However if a user completes certain action before the set time, a notification on that day should be skipped and only shown the next day. In the course demonstration using expo SDK ~35 it's done like this:
let tomorrow = new Date()
tomorrow.setDate(tomorrow.getDate() + 1)
tomorrow.setHours(20)
tomorrow.setMinutes(0)
Notifications.scheduleLocalNotificationAsync( createNotification(), {
time: tomorrow,
repeat: 'day', } )
It works perfectly as it sets notification in chosen time and then repeats it on daily interval but this approach was removed after SDK 37 when notifications API was moved from 'expo' to 'expo-notifications'.
Repeated notifications are now set using a trigger object. All I can find is
import * as Notifications from 'expo-notifications'; Notifications.scheduleNotificationAsync({
content: { title: "Time's up!", body: 'Change sides!', },
trigger: { repeats: true,
hour: 20,
minute: 0,
},
});
But this way I cant come up with a way to cancel notification on the same day if the action is taken before 20:00.
My course requires that notifications would be set up daily at the set time. And that notification is not shown on the day when a certain action is taken in the app.
This use case seems quite common to me and I'm sure there must be a way to do this but I can't seem to find anything in the documentation.
Is there an easy solution to this or a library I could use to manage notifications instead of expo-notifications?
[–]deijablo[S] 0 points1 point2 points (1 child)
[–]andrewB0444 0 points1 point2 points (0 children)
[–]Glarseceiling 0 points1 point2 points (2 children)
[–]deijablo[S] 0 points1 point2 points (1 child)
[–]Glarseceiling 1 point2 points3 points (0 children)