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

the task is dying out

Open SokolovRU opened this issue 2 years ago • 8 comments

maybe I'm testing it incorrectly, but when I launch the application and look at the console, the task works, but when I minimize the application, it stops running within a minute, even less.

SokolovRU avatar Nov 26 '22 18:11 SokolovRU

Have same issue, returning to foreground restores task again.

dragorwyin avatar Jan 02 '23 15:01 dragorwyin

Have the same problem, Android, "react": "^18.2.0", "react-native": "^0.70.6", "react-native-background-timer": "^2.4.1",

Interval stops after 1-2 minutes of running in the background.

punov avatar Jan 03 '23 12:01 punov

I was able to fix it by providing more permissions to the Application,

"Apps" > <Select your app> > Remove permissions if app is unused turned OFF
"Apps" > <Select your app> > Battery > Unrestricted 

I can assume it will not suit some of your needs, but if you have to make your app unstoppable, it can save your day.

punov avatar Jan 03 '23 13:01 punov

@punov you mean change those settings on your phone?

chj-damon avatar Jan 28 '23 06:01 chj-damon

@punov that work for me too, thanks man

robertsonasc avatar Feb 12 '23 23:02 robertsonasc

I have the same problem but for iOS 16.2, and using the following versions :

"react": "18.2.0",
"react-native": "0.71.2",
"react-native-background-timer": "^2.4.1",

On iOS, I can't access those permissions directly, do you know how I can fix that ? Maybe by requesting equivalent permission directly to the user ? I was thinking about "Background app refresh" but my app doesn't even show up there

Flobeney avatar Mar 07 '23 15:03 Flobeney

Same here (at least on iOs) and the same struggle with react-native-background-actions

To me it seems this is just normal behaviour, since the ios part relies on beginBackgroundTaskWithname. As it states there the background tasks have an assigned time which they get to run, after that time the process is stalled.

@ocetnik Would it be possible to use "normal" Background Tasks in iOs to prevent the process to be stopped so soon?

Im willing to contribute to make this happen, I just don't know if Background Tasks will perform as desired

lauhon avatar Aug 09 '23 09:08 lauhon

We solved this on Android by asking the user to turn off the battery optimisation (as this is the issue).

Check if the user has battery optimisation turned on:

const isIgnoring = await BackgroundGeolocation.deviceSettings.isIgnoringBatteryOptimizations();

If isIgnoring is false, ask the user to turn it off (using an alert or modal or whatever you like)

const request = await BackgroundGeolocation.deviceSettings.showIgnoreBatteryOptimizations();

And in the onPress:

BackgroundGeolocation.deviceSettings.show(request)

reference: https://transistorsoft.github.io/react-native-background-geolocation/interfaces/devicesettings.html

abakers avatar Oct 04 '23 14:10 abakers