Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

React Native: wake a locked phone and play a sound

$
0
0

I am building a running app that shows a timer. When the timer reaches 0 seconds a sound is played. I use React Native Sound for playback. I use an interval on componentDidMount for counting the seconds:

componentDidMount() {    this.recalcTotalSeconds();    KeepAwake.activate();    this._interval = setInterval(() => {        this.step();    }, 999);}

It works nicely as long as the phone is unlocked. When the phone is locked the interval is not fired and the sound is not played. As a first measure I uploaded a version with Keep Awake that prevents the screen from locking. I am looking for a battery-friendly solution.

timer screen

How can I set a timeout to wake the phone up or at least play a sound to alert the user to unlock the phone? How can I play sound in the background when the phone is locked?


Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>