I developed an app that uses background fetch. I set the minimum interval between updates to minimum:
[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
I thought that this value is saved by the system, so I don't have to set it again when/if the app restarts. However, I've just noticed that the last background fetch on one of my devices was two weeks ago. I know, that the interval between updates can vary, but I don't think that two weeks is normal. Especially considering the fact that it worked for several months, calling background update every 20-30 minutes.
Unfortunately, I couldn't find a way to get the MinimumBackgroundFetchInterval
to check my theory (does anyone know how to get it by the way?). I only checked application.backgroundRefreshStatus
, and it is equal to UIBackgroundRefreshStatusAvailable
, but I think (I'm not sure) this only means that the user allows the app to use background updates.
If you need to execute code when your app isn't running, there are several options open to you depending on what you're trying to do. Background fetch will let your app run in the background for about 30 seconds at scheduled intervals. The goal of this is to fetch data and prepare your UI for when the app runs next.
You need to enable Background Mode in your project settings under capabilities tab. Under background modes you will find a few modes that satisfy various purposes of running an app in background.
Well, it turned out that NO, we don't need to call setMinimumBackgroundFetchInterval
every time the app restarts.
I had an experiment: I set it to UIApplicationBackgroundFetchIntervalMinimum
(turned the background fetch on), then shut the app down manually (via the task manager) and then restarted it, but didn't call to setMinimumBackgroundFetchInterval
. The app continued to perform background fetches as it used to.
I hope, that this information will be helpful for someone, since it is not explicitly stated in the documentation (at least, I didn't see it). As for me, I have to find another possible reason why my app didn't work for two weeks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With