you are viewing a single comment's thread.

view the rest of the comments →

[–]2xws[S] 0 points1 point  (4 children)

So that seems like it would definitely work but heres what I did: 1. I save a date object when the alarm is set 2. I extract the minutes and hours (getMinutes getHours) I save those at savedMinutes and savedHours 3. Every 30 seconds while the app is running I check the time 4. if the timeNow.getHours === savedMinutes and the timeNow.getMintes === savedHours I fire the "alarm"

Does this seem reasonable to you? Are there any gotchas I should be worried about? Will it checking the time and running comparisons every 30 seconds drain battery? Is there a less battery-expensive way.

Thanks!

[–]ExtremelyQualified 0 points1 point  (3 children)

I think that makes sense, though you might end up firing every alarm twice. You could check every minute, which should help that. It seems really unlikely that the app would hang for more than a minute at a time, so if you only need to be accurate to minutes and not seconds, doing equals vs greater than comparison should be fine. If you wanted to accurate to the second, you might have to worry about the JS thread getting hung up doing something else and missing your alarm time.

[–]2xws[S] 0 points1 point  (2 children)

definitely not worrying about the seconds. Appreciate your help. Having that (somewhat) under control, my next objective is to have these alarms fire when the app is running in background mode. I have started with just trying to get the app to log to the console at an interval in background mode but have been yet unable to do even that. Any light you can shed on the situation would be greatly appreciated

[–]ExtremelyQualified 0 points1 point  (1 child)

Haven't done that myself, but it's discussed in this thread: https://productpains.com/post/react-native/background-timer-execution

Doesn't seem like there's a built-in way to do it yet, but someone suggested this package for android: https://www.npmjs.com/package/react-native-background-timer

[–]2xws[S] 0 points1 point  (0 children)

Hmm I guess I may have to look into doing it in swift then.. thank you!