background-processing
Schedule and execute background work on iOS using BGTaskScheduler. Use when registering BGAppRefreshTask for short background fetches, BGProcessingTask for long-running maintenance, BGContinuedProcessingTask (iOS 26+) for foreground-started work that continues in background, background URLSession do
By dpearson2699 · 3,360 installs
npx skills add dpearson2699/swift-ios-skills --skill background-processing
Source repository · Upstream listing
Background Processing
Register, schedule, and execute background work on iOS using the BackgroundTasks
framework, background URLSession, and background push notifications.
Contents
[Info.plist Configuration]( infoplist configuration)
[BGTaskScheduler Registration]( bgtaskscheduler registration)
[BGAppRefreshTask Patterns]( bgapprefreshtask patterns)
[BGProcessingTask Patterns]( bgprocessingtask patterns)
[BGContinuedProcessingTask (iOS 26+)]( bgcontinuedprocessingtask ios 26)
[Background URLSession Downloads]( background urlsession downloads)
[Background Push Triggers]( background push triggers)
[Common Mistakes]( common mistakes)
[Review Checklist]( review checklist)
[References]( references)
Info.plist Configuration
Every task identifier must be declared in Info.plist under
BGTaskSchedulerPermittedIdentifiers , or submit( :) throws
BGTaskScheduler.Error.Code.notPermitted .
Also enable the required UIBackgroundModes :
In Xcode: target Signing & Capabilities Background Modes enable "Background fetch" and "Background processing".
BGTaskScheduler Registration
Register handlers before app launch completes. In UIKit, register in
application( :didFinishLaunchingWithOptions:) ; in SwiftUI, register in App.init() .
UIKit Registration
SwiftUI Registration
BGAppRefreshTask Patterns
Short lived tasks (~30 seconds) for fetching small data updates. The system
decides when to launch; earliestBeginDate is only a lower bound hint.
BGProcessingTask Patterns
Long running tasks (minutes) for maintenance, data processing, or cleanup.
They run while the device is idle and can require external power; the same
earliestBeginDate lower bound rule applies.
BGContinuedProcessingTask (iOS 26+)
A task initiated in the foreground by a user action that continues running in the
background. The system displays progress via a Live Activity. Conforms to
ProgressReporting .
Availability: iOS 26.0+, iPadOS 26.0+
Unlike BGAppRefreshTask and BGProcessingTask , this task starts immediately
from the foreground. The system can terminate it under resource pressure,
prioritizing tasks that report minimal progress first. Set expirationHandler for user or system cancellation, cancel in flight work, and clean up partial output before reporting completion.
For GPU work, check support and enable Background GPU Access ( com.apple.developer.background tasks.continued processing.gpu ):
Background URLSession Downloads
Use URLSessionConfiguration.background for downloads that continue even after
the app is suspended or terminated. The system handles the transfer out of
process.
Handle app relaunch — store and invoke the system completion handler:
Background Push Triggers
Silent push notifications wake your app briefly to fetch new content. Set
content available: 1 in the push payload.
Send the APNs request with apns push type: background and
apns priority: 5 . Background push delivery is low priority and not
guaranteed; keep sends infrequent, generally no more than two or three per
hour.
Handle in AppDelegate:
Enable "Remote notifications" in Background Modes and register:
Common Mistakes
1. Missing Info.plist identifiers
2. Not calling setTaskCompleted(success:)
Use the canonical app refresh or processing handler above: every success,
failure, and cancellation path reports completion exactly once.
3. Ignoring the expiration handler
Use the same canonical handler to cancel in flight work and report failure from
expirationHandler .
4. Scheduling too frequently
The scheduling sections own the lower bound rule. Avoid minute scale refresh
requests; the system still chooses actual launch time.
5. Over relying on background time
Review Checklist
[ ] All task identifiers listed in BGTaskSchedulerPermittedIdentifiers
[ ] Required UIBackgroundModes enabled ( fetch , processing )
[ ] Tasks registered before app launch completes
[ ] setTaskCompleted(success:) called on every code path
[ ] expirationHandler set and cancels in flight work
[ ] Next task scheduled inside the handler (re schedule pattern)
[ ] earliestBeginDate uses reasonable intervals and is treated as a hint
[ ] Background URLSession uses delegate (not async/closures)
[ ] Background URLSession file moved in didFinishDownloadingTo before return
[ ] handleEventsForBackgroundURLSession stores and calls completion handler
[ ] Background push payload includes content available: 1
[ ] Background push APNs request uses apns push type: background and apns priority: 5
[ ] fetchCompletionHandler called promptly with correct result
[ ] BGContinuedProcessingTask reports progress via ProgressReporting
[ ] Work is incremental and cancellation safe ( Task.checkCancellation() )
[ ] No blocking synchronous work in task handlers
References
See [references/background task patterns.md](references/background task patterns.md) for extended patterns, background
URLSession edge cases, debugging with simulated launches, and background push
best practices.
[BGTaskScheduler](https://sosumi.ai/documentation/backgroundtasks/bgtaskscheduler)
[BGAppRefreshTask](https://sosumi.ai/documentation/backgroundtasks/bgapprefreshtask)
[BGProcessingTask](https://sosumi.ai/documentation/backgroundtasks/bgprocessingtask)
[BGContinuedProcessingTask](https://sosumi.ai/documentation/backgroundtasks/bgcontinuedprocessingtask) (iOS 26+)
[BGContinuedProcessingTaskRequest](https://sosumi.ai/documentation/backgroundtasks/bgcontinuedprocessingtaskrequest) (iOS 26+)
[Using background tasks to update your app](https://sosumi.ai/documentation/uikit/using background tasks to update your app)
[Performing long running tasks on iOS and iPadOS](https://sosumi.ai/documentation/backgroundtasks/performing long running tasks on ios and ipados)