Expert lifecycle decisions for iOS/tvOS: when SwiftUI lifecycle vs SceneDelegate, background task strategies, state restoration trade-offs, and launch optimization. Use when managing app state transitions, handling background work, or debugging lifecycle issues. Trigger keywords: lifecycle, scenePhase, SceneDelegate, AppDelegate, background task, state restoration, launch time, didFinishLaunching, applicationWillTerminate, sceneDidBecomeActive
View on GitHubKaakati/rails-enterprise-dev
reactree-ios-dev
January 25, 2026
Select agents to install to:
npx add-skill https://github.com/Kaakati/rails-enterprise-dev/blob/main/plugins/reactree-ios-dev/skills/app-lifecycle/SKILL.md -a claude-code --skill app-lifecycleInstallation paths:
.claude/skills/app-lifecycle/# App Lifecycle — Expert Decisions
Expert decision frameworks for app lifecycle choices. Claude knows scenePhase and SceneDelegate — this skill provides judgment calls for architecture decisions and background task trade-offs.
---
## Decision Trees
### Lifecycle API Selection
```
What's your project setup?
├─ Pure SwiftUI app (iOS 14+)
│ └─ @main App + scenePhase
│ Simplest approach, sufficient for most apps
│
├─ Need UIKit integration
│ └─ SceneDelegate + UIHostingController
│ Required for some third-party SDKs
│
├─ Need pre-launch setup
│ └─ AppDelegate + SceneDelegate
│ SDK initialization, remote notifications
│
└─ Legacy app (pre-iOS 13)
└─ AppDelegate only
window property on AppDelegate
```
**The trap**: Using SceneDelegate when pure SwiftUI suffices. scenePhase covers most use cases without the boilerplate.
### Background Task Strategy
```
What work needs to happen in background?
├─ Quick save (< 5 seconds)
│ └─ UIApplication.beginBackgroundTask
│ Request extra time in sceneDidEnterBackground
│
├─ Network sync (< 30 seconds)
│ └─ BGAppRefreshTask
│ System schedules, best-effort timing
│
├─ Large download/upload
│ └─ Background URL Session
│ Continues even after app termination
│
├─ Location tracking
│ └─ Location background mode
│ Significant change or continuous
│
└─ Long processing (> 30 seconds)
└─ BGProcessingTask
Runs during charging, overnight
```
### State Restoration Approach
```
What state needs restoration?
├─ Simple navigation state
│ └─ @SceneStorage
│ Per-scene, automatic, Codable types only
│
├─ Complex navigation + data
│ └─ @AppStorage + manual encoding
│ More control, cross-scene sharing
│
├─ UIKit-based navigation
│ └─ State restoration identifiers
│ encodeRestorableState/decodeRestorableState
│
└─ Don't need restoration
└─ Start fresh each launch
Some apps are better this way
```
### Launch Optimization Priority
```
What's blocking your launch time?
├─ S