$npx -y skills add rshankras/claude-code-apple-skills --skill background-processingGenerates 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.
| 1 | # Background Processing Generator |
| 2 | |
| 3 | 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. |
| 4 | |
| 5 | ## When This Skill Activates |
| 6 | |
| 7 | Use this skill when the user: |
| 8 | - Asks to "add background processing" or "background tasks" |
| 9 | - Mentions "BGTaskScheduler" or "BGAppRefreshTask" or "BGProcessingTask" |
| 10 | - Wants "background refresh" or "periodic background updates" |
| 11 | - Asks about "background downloads" or "background uploads" |
| 12 | - Mentions "silent push" or "content-available push notifications" |
| 13 | - Wants data to sync or update while the app is in the background |
| 14 | - Asks about "background fetch" or "background execution" |
| 15 | |
| 16 | ## Pre-Generation Checks |
| 17 | |
| 18 | ### 1. Project Context Detection |
| 19 | - [ ] Check deployment target (BGTaskScheduler requires iOS 13+) |
| 20 | - [ ] Check Swift version (requires Swift 5.9+) |
| 21 | - [ ] Check for @Observable support (iOS 17+ / macOS 14+) |
| 22 | - [ ] Identify source file locations |
| 23 | |
| 24 | ### 2. Existing Background Task Detection |
| 25 | Search for existing background task code: |
| 26 | ``` |
| 27 | Glob: **/*BackgroundTask*.swift, **/*BGTask*.swift, **/*BackgroundDownload*.swift |
| 28 | Grep: "BGTaskScheduler" or "BGAppRefreshTask" or "BGProcessingTask" or "backgroundSession" |
| 29 | ``` |
| 30 | |
| 31 | If existing background code found: |
| 32 | - Ask if user wants to replace or augment it |
| 33 | - If augmenting, identify what is missing and generate only those pieces |
| 34 | |
| 35 | ### 3. Info.plist Check |
| 36 | Search for existing background modes configuration: |
| 37 | ``` |
| 38 | Grep: "BGTaskSchedulerPermittedIdentifiers" or "UIBackgroundModes" |
| 39 | ``` |
| 40 | |
| 41 | Check for push notification entitlements if silent push is needed: |
| 42 | ``` |
| 43 | Glob: **/*.entitlements |
| 44 | Grep: "aps-environment" |
| 45 | ``` |
| 46 | |
| 47 | ## Configuration Questions |
| 48 | |
| 49 | Ask user via AskUserQuestion: |
| 50 | |
| 51 | 1. **What background processing do you need?** |
| 52 | - App refresh (lightweight periodic updates -- weather, feeds, content) |
| 53 | - Data processing (long-running -- database cleanup, ML model updates, large syncs) |
| 54 | - Background downloads (files, media, assets that survive app termination) |
| 55 | - Silent push notifications (server-triggered content updates) |
| 56 | - Multiple (select which combination) |
| 57 | |
| 58 | 2. **How often should background tasks run?** |
| 59 | - Hourly (system decides exact timing, best-effort) |
| 60 | - Every few hours (recommended for most apps) |
| 61 | - Daily (content that changes infrequently) |
| 62 | - On content change via push (server triggers update with silent push) |
| 63 | |
| 64 | 3. **Does the task need network access?** |
| 65 | - Yes -- needs background fetch or download capability |
| 66 | - No -- local processing only (database maintenance, cleanup) |
| 67 | |
| 68 | ## Generation Process |
| 69 | |
| 70 | ### Step 1: Read Templates |
| 71 | Read `templates.md` for production Swift code. |
| 72 | |
| 73 | ### Step 2: Create Core Files |
| 74 | Generate these files: |
| 75 | 1. `BackgroundTaskManager.swift` -- Central manager for registering and scheduling all background tasks |
| 76 | 2. `BackgroundTaskConfiguration.swift` -- Info.plist keys, entitlements, and task identifier constants |
| 77 | |
| 78 | ### Step 3: Create Feature-Specific Files |
| 79 | Based on configuration: |
| 80 | 3. `BackgroundDownloadManager.swift` -- If background downloads selected |
| 81 | 4. `SilentPushHandler.swift` -- If silent push selected |
| 82 | |
| 83 | ### Step 4: Determine File Location |
| 84 | Check project structure: |
| 85 | - If `Sources/` exists -> `Sources/BackgroundProcessing/` |
| 86 | - If `App/` exists -> `App/BackgroundProcessing/` |
| 87 | - Otherwise -> `BackgroundProcessing/` |
| 88 | |
| 89 | ## Output Format |
| 90 | |
| 91 | After generation, provide: |
| 92 | |
| 93 | ### Files Created |
| 94 | ``` |
| 95 | BackgroundProcessing/ |
| 96 | ├── BackgroundTaskManager.swift # BGTaskScheduler registration & scheduling |
| 97 | ├── BackgroundTaskConfiguration.swift # Task identifiers and Info.plist config |
| 98 | ├── BackgroundDownloadManager.swift # Background URLSession downloads (optional) |
| 99 | └── SilentPushHandler.swift # Silent push handling (optional) |
| 100 | ``` |
| 101 | |
| 102 | ### Integration with App Lifecycle |
| 103 | |
| 104 | **Register tasks at app launch (must happen before app finishes launching):** |
| 105 | ```swift |
| 106 | @main |
| 107 | struct MyApp: App { |
| 108 | @UIApplicationDelegateAdaptor private var appDelegate: AppDelegate |
| 109 | |
| 110 | var body: some Scene { |
| 111 | WindowGroup { |
| 112 | ContentView() |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | class AppDelegate: NSObject, UIApplicationDelegate { |
| 118 | func application( |
| 119 | _ application: UIApplication, |
| 120 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? |
| 121 | ) -> Bool { |
| 122 | BackgroundTaskManager.shared.registerTasks() |
| 123 | return true |
| 124 | } |
| 125 | } |
| 126 | ``` |
| 127 | |
| 128 | **Schedule refresh when app enters background:** |
| 129 | ```swift |
| 130 | struct ContentView: View { |