iOS background execution with AI agents: BGTaskScheduler, URLSession and silent push
Do not invent a forever-background timer. Register BGTaskScheduler identifiers before launch finishes, bracket short work with beginBackgroundTask, use a background URLSession for transfers, and treat silent push as opportunistic. Install a background skill (or Axiom's background-processing pack), then verify every API on developer.apple.com.
Last updated:
This page is about getting a coding agent to schedule deferred work correctly, finish short background assertions, transfer files after suspension, and handle silent push without inventing always-on execution. For WidgetKit timelines and Live Activities, see WidgetKit and Live Activities with AI agents. For App Intents that may trigger work, see App Intents with AI agents.
What the agent has to get right
Apple's Background Tasks framework is the contract for deferred work on iOS and iPadOS. Agents trained on Android-style services still invent perpetual background timers, skip BGTaskScheduler registration, and ignore expiration handlers.
Four layers show up in almost every background PR:
Scheduled work — BGTaskScheduler with
BGAppRefreshTask/BGProcessingTask(and newer continued-processing types where available), identifiers listed inBGTaskSchedulerPermittedIdentifiers, and registration before launch finishes.Short assertions — beginBackgroundTask(expirationHandler:) /
endBackgroundTaskfor a few seconds of wrap-up after the user leaves; always balance begin/end, including in the expiration handler.Transfers — Downloading files in the background with
URLSessionConfiguration.background(withIdentifier:), a real delegate, and the relaunch path (handleEventsForBackgroundURLSession).Wakeups — silent/background push (
content-available,apns-push-type: background) as opportunistic only; pair with the rightUIBackgroundModesinstead of inventing a keep-alive socket.
Rules worth adding to AGENTS.md or CLAUDE.md:
Background: never invent a forever-running timer. Register every BGTaskScheduler identifier before launch returns. Bracket short work with beginBackgroundTask and end it on every path. Use a background URLSession for uploads/downloads that must continue after suspension. Treat silent push as discretionary. Confirm APIs on developer.apple.com.
Step 1: install a background skill
Ask the agent to:
Install Background Execution (
npx skills add https://github.com/n0an/Background-Execution-Agent-Skill) for BGTaskScheduler, task assertions, background URLSession, silent push and UIBackgroundModes guidance.Or install Axiom (
/plugin marketplace add CharlesWiltgen/Axiom, then install the axiom plugin) and invoke its background-processing / push-notifications skills.add Apple Native Skills (
apple-system-integration) for BGTaskScheduler plus User Notifications in one pack, or Claude Apple Dev Skills for macOS/watchOS background references.
Honest limit: one dedicated background skill plus a short AGENTS.md rule beats installing every platform pack at once.
Step 2: register before you schedule
Point the agent at BGTaskScheduler. Require:
Info.plist — every task identifier under
BGTaskSchedulerPermittedIdentifiers, plus the matchingUIBackgroundModesvalues.Registration timing —
BGTaskScheduler.shared.registerfor each identifier before launch finishes.Submit as a request —
submit(_:)does not promise a wall-clock fire time.Completion — call
setTaskCompleted(success:)(and handle expiration) so the system can budget future work.
Step 3: assertions, URLSession and silent push
For work that starts in the foreground:
Use
beginBackgroundTask(expirationHandler:)for short wrap-up; end the task in success, failure and expiration paths.For file transfers that must continue after suspension, follow Downloading files in the background with a background
URLSessionConfiguration, a dedicated identifier and the relaunch delegate callbacks.For silent push, set
apns-push-typetobackgroundand treat delivery as coalesced and discretionary—not a substitute for BGTaskScheduler.
Step 4: review before merge
Run the background skill (or Axiom's background-processing diag) on the diff. Treat missing registration, unbalanced assertions, completion-handler misuse on background sessions and invented keep-alive timers as merge blockers. A skill review does not replace a device test under Low Power Mode and disabled Background App Refresh.
Tools compared (4)
| Tool | Best for | Agents (README) | Install (README) | License | Stars | Last push |
|---|---|---|---|---|---|---|
| Background Execution (n0an) | Dedicated BGTaskScheduler, beginBackgroundTask, background URLSession, silent push, UIBackgroundModes and anti-patterns | Claude Code, Cursor, Codex, Gemini | npx skills add https://github.com/n0an/Background-Execution-Agent-Skill | MIT | 13 | 8 Sep 2026 |
| Axiom (CharlesWiltgen) | Full xOS suite with background-processing, background-assets and push-notifications skills plus diagnostics | Claude Code, Codex | /plugin marketplace add CharlesWiltgen/Axiom then install axiom from /plugin | MIT | 1242 | 31 Oct 2026 |
| Apple Native Skills (Yar177) | apple-system-integration skill covering BGTaskScheduler, background URLSession, User Notifications, App Intents and widgets | Claude Code, Cursor, Codex, Gemini, Windsurf | npx skills add Yar177/appleNativeSkills --skill apple-system-integration | MIT | 0 | 17 Jun 2026 |
| Claude Apple Dev Skills (laramarcodes) | Platform packs with macOS automation-and-background and watchOS background-and-runtime references (plus visionOS/iOS scaffolds) | Claude Code, Cursor, Codex | npx skills add laramarcodes/claude-apple-dev-skills | MIT | 4 | 29 Jul 2026 |
⚠ = no push for more than 4 weeks. Axiom (31 Oct) is fresh. Background Execution (8 Sep), Apple Native Skills (17 Jun) and Claude Apple Dev Skills (29 Jul) are older—verify guidance against current Background Tasks and URLSession docs before treating every recommendation as final.
Which one to pick:
Default dedicated background skill: Background Execution.
Already on Axiom for Apple platforms: use Axiom's background-processing / push skills instead of a second pack.
system-integration pack that includes BGTaskScheduler: Apple Native Skills (
apple-system-integration).macOS/watchOS background notes inside a multi-platform pack: Claude Apple Dev Skills.
A prompt that keeps the agent honest
Setting up the agent itself: Claude Code for iOS development, Codex for iOS development or Cursor rules for SwiftUI.
Register a BGAppRefreshTask identifier in Info.plist and in code before launch returns. Schedule it with BGTaskScheduler; do not promise a fire time. For the sync that starts when the user leaves, use beginBackgroundTask and end it in the expiration handler. Put the download on a background URLSession with a stable identifier. Do not invent a keep-alive timer. Run a background skill review on the diff and confirm APIs on developer.apple.com.
FAQ
- What is iOS background execution work for AI coding agents?
- Background execution work for agents means teaching Claude Code, Cursor or Codex to schedule deferred work with BGTaskScheduler, finish short tasks with beginBackgroundTask, transfer files with a background URLSession, and handle silent push without inventing always-on timers that iOS will not grant.
- Will a BGAppRefreshTask run at the exact time the agent schedules?
- No. Apple's Background Tasks framework treats scheduled work as opportunistic. The system decides when or whether a BGAppRefreshTask or BGProcessingTask runs based on battery, usage and other constraints. Agents must treat submit as a request, not a guarantee.
- How should the agent finish work when the user backgrounds the app?
- For short wrap-up, use UIApplication beginBackgroundTask(expirationHandler:) and end the task in every path, including the expiration handler. For longer deferred work, register and schedule BGTaskScheduler tasks. Do not keep spinning after the expiration handler runs.
- Which background tool should I install first?
- Start with the dedicated Background Execution skill for BGTaskScheduler, background URLSession, task assertions and silent push. If you already use Axiom, invoke its background-processing and push-notifications skills instead of stacking every pack. Apple Native Skills' apple-system-integration skill adds BGTaskScheduler plus notifications in one install.
- Does a passing background-skill review mean tasks will run in production?
- No. Skills catch registration mistakes, missing expiration handlers and wrong UIBackgroundModes. Production scheduling still depends on Apple's discretionary budget, Low Power Mode, background refresh status and user behavior. Confirm identifiers, Info.plist and APIs on developer.apple.com, then test on a device.