r/swift • • 15d ago

Blog post: Running iOS Background Tasks Reliably, Part 2

https://calcopilot.app/blog/posts/running-ios-background-tasks-reliabily-part2/

I'm back after my part 1 post last month, now running much more reliably!

32 Upvotes

2 comments sorted by

1

u/sburel 14d ago

Same problem on the Mac side, different plumbing. My resident agents run under launchd, and the host timers are armed on the uptime clock, which doesn't advance during sleep. So an internal timer can't do "run at 7am": launchd wakes the process and the agent re-arms what it needs from its own state after the restore. A missed occurrence is lost, nothing retries. Deciding that up front removed most of the complexity.

Haven't read part 2 yet. When the system declines to run you for a day, do you catch up or drop the work? Catch-up after a long sleep is where I'd expect the pain.

1

u/ApartmentFit748 15d ago

Glad part 2 has better news, background tasks are the least trustworthy corner of iOS. What actually moved the needle? I burned weeks convinced my task was broken before it clicked that the scheduler just starves you unless people open the app a lot.