Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Generates background processing infrastructure with BGTaskScheduler, background refresh, background downloads, and silent push handling. Use when user needs background tasks, periodic refresh, background URLSession downloads, or silent push notification processing.
.claude/skills/rshankras-background-processing/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-07 | ✗→✓ | ▲ Improved | 124% | 0% |
| case-14 | ✗→✓ | ▲ Improved | 81% | 0% |
| case-15 | ✗→✓ | ▲ Improved | 39% | 0% |
| case-17 | ✗→✓ | ▲ Improved | 50% | 0% |
| case-18 | ✗→✓ | ▲ Improved | 112% | 0% |
Generate production background processing infrastructure -- BGTaskScheduler for periodic refresh and long-running tasks, background URLSession for downloads/uploads that survive app termination, and silent push handling for server-triggered updates.
Use this skill when the user:
Search for existing background task code:
Glob: **/*BackgroundTask*.swift, **/*BGTask*.swift, **/*BackgroundDownload*.swift
Grep: "BGTaskScheduler" or "BGAppRefreshTask" or "BGProcessingTask" or "backgroundSession"If existing background code found:
Search for existing background modes configuration:
Grep: "BGTaskSchedulerPermittedIdentifiers" or "UIBackgroundModes"Check for push notification entitlements if silent push is needed:
Glob: **/*.entitlements
Grep: "aps-environment"Ask user via AskUserQuestion:
Read templates.md for production Swift code.
Generate these files:
BackgroundTaskManager.swift -- Central manager for registering and scheduling all background tasksBackgroundTaskConfiguration.swift -- Info.plist keys, entitlements, and task identifier constantsBased on configuration:
BackgroundDownloadManager.swift -- If background downloads selectedSilentPushHandler.swift -- If silent push selectedCheck project structure:
Sources/ exists -> Sources/BackgroundProcessing/App/ exists -> App/BackgroundProcessing/BackgroundProcessing/After generation, provide:
BackgroundProcessing/
├── BackgroundTaskManager.swift # BGTaskScheduler registration & scheduling
├── BackgroundTaskConfiguration.swift # Task identifiers and Info.plist config
├── BackgroundDownloadManager.swift # Background URLSession downloads (optional)
└── SilentPushHandler.swift # Silent push handling (optional)Register tasks at app launch (must happen before app finishes launching):
swift@main struct MyApp: App { @UIApplicationDelegateAdaptor private var appDelegate: AppDelegate var body: some Scene { WindowGroup { ContentView() } } } class AppDelegate: NSObject, UIApplicationDelegate { func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { BackgroundTaskManager.shared.registerTasks() return true } }
Schedule refresh when app enters background:
swiftstruct ContentView: View { @Environment(\.scenePhase) private var scenePhase var body: some View { NavigationStack { FeedView() } .onChange(of: scenePhase) { _, newPhase in if newPhase == .background { BackgroundTaskManager.shared.scheduleAppRefresh() } } } }
Start a background download:
swiftfunc downloadAsset(from url: URL) { BackgroundDownloadManager.shared.startDownload(from: url) }
Handle silent push in AppDelegate:
swiftfunc application( _ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any] ) async -> UIBackgroundFetchResult { await SilentPushHandler.shared.handle(userInfo: userInfo) }
Simulate background task in Xcode debugger (LLDB):
e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"com.app.refresh"]Simulate expiration:
e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateExpirationForTaskWithIdentifier:@"com.app.refresh"]Test background download:
swift#if DEBUG func simulateBackgroundDownload() { let testURL = URL(string: "https://example.com/test-asset.zip")! BackgroundDownloadManager.shared.startDownload(from: testURL) } #endif
Add to Info.plist:
xml<key>BGTaskSchedulerPermittedIdentifiers</key> <array> <string>com.app.refresh</string> <string>com.app.processing</string> </array>
In Xcode: Target > Signing & Capabilities > Background Modes:
Always schedule the next refresh when the app goes to background. The system decides when to actually run it.
swiftBackgroundTaskManager.shared.scheduleAppRefresh()
BGProcessingTask can run for minutes, but always handle the expirationHandler to save progress.
swifttask.expirationHandler = { // Save partial progress so next run can resume processingJob.saveCheckpoint() }
swift// Only process on Wi-Fi + power let request = BGProcessingTaskRequest(identifier: taskID) request.requiresNetworkConnectivity = true request.requiresExternalPower = true
BGTaskScheduler.shared.register(forTaskWithIdentifier:) must be called during didFinishLaunchingWithOptions. If called later, the registration silently fails. Always register in AppDelegate, never in a View.
The system decides when to run background tasks based on battery, network, user patterns, and frequency. You cannot guarantee exact timing. earliestBeginDate is a hint, not a guarantee.
Background URLSession delivers delegate callbacks even if the app was terminated and relaunched. The session must be recreated with the same identifier, and application(_:handleEventsForBackgroundURLSession:completionHandler:) must be implemented.
Silent push notifications are rate-limited by APNs. If you send too many, the system throttles them. Use them for important content changes, not periodic polling.
BGAppRefreshTask gives you approximately 30 seconds of execution time. For longer work, use BGProcessingTask instead (which can run for several minutes when conditions are met).
Background tasks do not run naturally on the Simulator. Use the LLDB _simulateLaunchForTaskWithIdentifier: command to trigger them manually during development.
generators/push-notifications -- Full push notification infrastructuregenerators/offline-queue -- Queue operations for when back onlineOther measured skills in the registry, with their headline benchmark lift.