How to create an alarm timer in react native

Viewed 210

I'm trying to replicate the native iOS timer with a light theme.

I've tried achieving the repeating sound functionality in the following ways and none worked while the app is in the background:

(I'm using react-native-background-timer and notifee)

  1. Recursively fire a "play sound" function when the timer is up - doesn't work on background, the sound is played only when I open the app

  2. Recursively schedule local notifications for when timer is up - only the first one fires, i.e. the notification when the timer is up, but after that nothing

If going with the notification route, I'd like to do something like:

notifee.displayNotification({ loopSound: true, ongoing: true })

Currently my last resort is scheduling a bunch of notifications ahead of time while the app is in the foreground, about 6 seconds apart each.

This is hacky and also if the user looks at the lock screen or notification center they'd see all these notifications which are one and the same.

I tried doing the same with passing the notification id, i.e. to update the same notification instead of creating a new one each time, but then the notification is only displayed once, at the latest scheduling.

Any ideas how to go about it?

0 Answers
Related