background-processing

Guide BGTaskScheduler registration, scheduling, and expiration handling for iOS background tasks.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/derKlinke/codex-config --skill background-processing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: background-processing
Source: https://github.com/derKlinke/codex-config/tree/main/skills/ios-background-processing
Command: npx skills add https://github.com/derKlinke/codex-config --skill background-processing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

iOS background execution is constrained and unpredictable. This Skill provides comprehensive guidance to implement, debug, and verify BGTaskScheduler tasks so they run reliably across app launches and system conditions.

Core Features & Use Cases

  • Registration and scheduling for BGAppRefreshTask, BGProcessingTask, BGContinuedProcessingTask, beginBackgroundTask, and Background URLSession.
  • Expiration handling, progressive task completion, and issues diagnosis with WWDC-backed scheduling factors.
  • Swift 6 cancellation integration to bridge expiration with cooperative cancellation in async code.

Quick Start

  1. Register a task in didFinishLaunchingWithOptions: BGTaskScheduler.shared.register(forTaskWithIdentifier: "com.yourapp.refresh", using: nil) { task in self.handleAppRefresh(task: task as! BGAppRefreshTask) }
  2. Schedule the task when the app goes to background: let request = BGAppRefreshTaskRequest(identifier: "com.yourapp.refresh") request.earliestBeginDate = Date(timeIntervalSinceNow: 15 * 60) try BGTaskScheduler.shared.submit(request)
  3. Implement the handler with an expirationHandler and completion: func handleAppRefresh(task: BGAppRefreshTask) { task.expirationHandler = { self.currentOperation?.cancel() } self.fetchLatestContent { _ in task.setTaskCompleted(success: true) } }

Frequently Asked Questions about background-processing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I schedule a BGAppRefreshTask reliably using BGTaskScheduler in iOS?

To schedule a BGAppRefreshTask reliably, register the task identifier in didFinishLaunchingWithOptions and submit a BGAppRefreshTaskRequest with an earliestBeginDate when the app enters background, ensuring proper system registration timing.

What is the best way to handle BGTaskScheduler expiration handlers for background tasks?

The best way to handle background task expiration is to assign an expirationHandler block to cancel ongoing operations, bridging expiration with Swift 6 cooperative cancellation, and then call setTaskCompleted to gracefully terminate.

Does background-processing guidance apply to BGProcessingTask and Background URLSession patterns?

Yes, background-processing guidance applies to BGProcessingTask, BGContinuedProcessingTask, beginBackgroundTask, and Background URLSession patterns, covering registration, scheduling, and expiration handling across app lifecycle events.

How do I integrate Swift 6 cancellation with iOS background task expiration handling?

Integrate Swift 6 cancellation with background task expiration by triggering cooperative cancellation in your async code within the expirationHandler, allowing progressive task completion before the system forcibly terminates your app.

Why does my BGAppRefreshTask fail to execute consistently across app launches?

Your BGAppRefreshTask may fail due to incorrect registration timing, missing earliestBeginDate thresholds, or ignoring WWDC-backed scheduling factors like system conditions and battery level, which constrain background execution unpredictably.