Search code examples
iosswiftxcodewatchkit

watchkit - capture when background refresh was ignored


In the apple dev documentation this is stated about scheduling background refreshes:

Background refresh tasks only trigger when the app is in the background. If the app is still running in the foreground at the scheduled time, the system ignores the task.

I am concerned about when the task is ignored. I haven't found any information on how to identify when the task was ignored. Does anyone know if there is any way to identify when a background task was ignored?

I am asking as I want to trigger a repeating background refresh every 60 minutes. If the application is open, I want to skip the background refresh for that moment and reschedule for the next 60 minutes. I can reschedule background app refreshes every time I execute a background app refresh, but if one is ignored the cycle is broken. (Unless there is a simpler way to trigger repeating refreshed, which would also help me).

Thanks for any help!


Solution

  • I couldn't find a solution for this, but with some hindsight I've got a workaround (which is probably better).

    Every time I schedule a background refresh, I store the expected date/time it should occur.

    Then, whenever I close the app, I check if the stored date/time is in the past. If it is, it means the last background refresh was interrupted (because it didn't run and therefore did not update the stored date/time).

    From there, I simply reschedule the background refresh again.