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

iOs Background Action stalls after background time

Open lauhon opened this issue 2 years ago • 5 comments
trafficstars

To me it seems this is just normal behavior 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.

@Rapsssito 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

(The same topic applies to react-native-background-timer)

lauhon avatar Aug 09 '23 09:08 lauhon

Hi @lauhon, you are more than welcome to send a PR! However, take a look at this comment here: https://stackoverflow.com/questions/58960411/how-to-get-your-ios-app-to-run-in-the-background-for-longer-than-3-minutes

We haven’t had the old 10 minute window for years so that is simply no longer applicable. That was reduced to 3 minutes in OS 7, and further reduced to 30 seconds in iOS 13. (There is a new concept of background tasks, for running tasks longer than 30 seconds, but the the OS will run these at its own discretion, e.g. at night, when the user is charging their device, so that’s not really applicable here).

Rapsssito avatar Sep 07 '23 09:09 Rapsssito

Nice to know. I will look into it as soon as I can.

Hopefully, the behavior of background tasks ends up making sense. I guess if it's not 100% intuitive I can add a setting/flag to control if the task should run as it's possible already, or with the background task API.

lauhon avatar Sep 13 '23 08:09 lauhon

FWIW, I have an app using this library on iOS that successfully stays in the background for 2+ hours. That being said, I'm also doing background audio and location. For me, the key to getting background execution to run longer was ensuring that the app's memory and cpu usage in the background was low.

techfoundrynz avatar Jan 26 '24 22:01 techfoundrynz

FWIW, I have an app using this library on iOS that successfully stays in the background for 2+ hours. That being said, I'm also doing background audio and location. For me, the key to getting background execution to run longer was ensuring that the app's memory and cpu usage in the background was low.

@contactsimonwilson can you share a snippet or gist on how you were able to implement this?

akinlekan28 avatar May 07 '24 16:05 akinlekan28