background-execution

Writes and reviews Swift code for background execution on Apple platforms using BGTaskScheduler, URLSession, and push.

1|Updated Aug 9, 2026
One-click install
npx skills add https://github.com/OMIXEC/all-in-one-swift-skills --skill background-execution-omixec
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: background-execution
Source: https://github.com/OMIXEC/all-in-one-swift-skills/tree/main/skills/background-execution
Command: npx skills add https://github.com/OMIXEC/all-in-one-swift-skills --skill background-execution-omixec

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Background execution on iOS and macOS is opportunistic and heavily constrained, so code that assumes tasks run promptly or at all fails silently in production. This Skill guides writing and reviewing Swift background-execution code so scheduled tasks, transfers, and wake-ups actually run and the app is not terminated. ## Core Features & Use Cases - API selection and routing: Decision trees map each goal (refresh, maintenance, file transfer, push wake-up, audio, location) to the correct API: BGAppRefreshTask, BGProcessingTask, BGContinuedProcessingTask, background URLSession, silent/VoIP push, or UIBackgroundModes. - Correctness review: Validates registration timing, expiration handlers, setTaskCompleted contracts, balanced beginBackgroundTask/endBackgroundTask calls, the background URLSession relaunch flow, and APNs header requirements. - Use Case: A developer's BGAppRefreshTask never fires on device. The Skill identifies that the handler was registered in .onAppear instead of App.init(), the identifier is missing from BGTaskSchedulerPermittedIdentifiers, and the next request was never rescheduled, then provides before/after fixes. ## Quick Start Ask the agent to review your Swift background-execution code or write a new BGTaskScheduler, background URLSession, or silent push implementation for your iOS app.

Frequently Asked Questions about background-execution

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

FAQPage Schema
How do I schedule a background task in Swift with BGTaskScheduler?▼

Register a handler in App.init() or didFinishLaunchingWithOptions, add the identifier to BGTaskSchedulerPermittedIdentifiers in Info.plist, then submit a BGAppRefreshTaskRequest or BGProcessingTaskRequest. Reschedule the next request as the first line of the launch handler since requests are one-shot.

Why does my BGAppRefreshTask never run on a real device?▼

Common causes are registering the handler lazily in view code, missing Info.plist entries, forgetting to reschedule the one-shot request, or the user force-quitting the app. Test on a real device using the lldb _simulateLaunchForTaskWithIdentifier command.

What is the difference between beginBackgroundTask and BGTaskScheduler?▼

beginBackgroundTask is a task assertion that finishes work already running as the app backgrounds, with roughly 30 seconds of runtime. BGTaskScheduler schedules future work the system runs at its chosen time. Using an assertion to start fresh long work is a common miscategorization.

How do I download large files in the background on iOS?▼

Use a URLSession created with URLSessionConfiguration.background(withIdentifier:) and a delegate; completion-handler methods do not work. Store the handler from handleEventsForBackgroundURLSession, recreate the session with the same identifier at relaunch, and call the stored handler from urlSessionDidFinishEvents on the main thread.

Why is my silent push notification not waking my iOS app?▼

Silent pushes require the apns-push-type: background header, apns-priority: 5, an aps dictionary containing only content-available, and the remote-notification background mode. Delivery is throttled, coalesced, and never delivered to force-quit apps, so it is not reliable for time-critical updates.

Can I record audio in the background with the screen locked on iOS?▼

Yes, with the audio UIBackgroundMode plus an active AVAudioSession using the .playAndRecord or .record category. You must declare NSMicrophoneUsageDescription, request record permission, and handle interruptions and route changes or capture stops silently.