react-native-background-timer icon indicating copy to clipboard operation
react-native-background-timer copied to clipboard

on ios14.3, bk timer only survive for 30s after switch to background run

Open code-assist opened this issue 4 years ago • 9 comments

On iOS 14.3, BackgroundTimer.runBackgroundTimer only run 30 second, the same as setInterval.

Does this work as design ?

BackgroundTimer.runBackgroundTimer(()=>{
            console.log("BackgroundTimer: Hello world. Now is: ", (new Date()).toLocaleString());
        },2000);

setInterval(()=>{
            console.log("setInterval: Hello world. Now is: ", (new Date()).toLocaleString());
        },2000)

code-assist avatar Jan 14 '21 04:01 code-assist

same here

ramyx avatar Jan 15 '21 03:01 ramyx

I am also facing same problem...any solution??

Prithhiraj avatar Jan 15 '21 06:01 Prithhiraj

same here

Arcaneless avatar Jan 16 '21 17:01 Arcaneless

After doing some research, iOS will kill the background timer after some amount of time. There is no way to run a long background timer except watching the location continuously or your app is playing music in the background. I solved my issue by watching user's location in the background. The timer will run as long as the location updates.

Arcaneless avatar Jan 17 '21 11:01 Arcaneless

any solution??

Ryan-cyi avatar Jan 27 '21 03:01 Ryan-cyi

any solution

yasir-syed avatar Mar 12 '21 16:03 yasir-syed

Did someone find any solution?

I've tried this package: react-native-track-player It's keep my timer to work for more than 30 seconds, I've even reached full circle of 25 min to work in background.

But it's working only on simulator, on real device it's stop after 30 sec :(

kirill-martynov avatar Apr 16 '21 07:04 kirill-martynov

I was trying to build pomodoro timer.

I thought running timer in background would be a good idea, but I was wrong, so I've decided to do something else: When I'm starting my timer I'm saving start time in storage and creating scheduled push notification so my user will get notification when timer is done.

When I'm going back to app from background state to foreground I'm checking difference between start time and current time and do some actions.

Maybe it will help someone

kirill-martynov avatar Apr 16 '21 16:04 kirill-martynov

here is a solution https://codeburst.io/the-definitive-guide-to-react-native-background-processing-51df02540433 https://developer.apple.com/documentation/watchkit/background_execution/enabling_background_sessions

IgarMikhailov avatar Aug 19 '21 12:08 IgarMikhailov