react-native-background-timer
react-native-background-timer copied to clipboard
the task is dying out
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.
Have same issue, returning to foreground restores task again.
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.
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 you mean change those settings on your phone?
@punov that work for me too, thanks man
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
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
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