home / skills / hoangnguyen0403 / agent-skills-standard / app-lifecycle

app-lifecycle skill

/skills/ios/app-lifecycle

This skill guides iOS app lifecycle best practices, promoting lean AppDelegate usage, SceneDelegate coordination, and robust deep linking and background task

npx playbooks add skill hoangnguyen0403/agent-skills-standard --skill app-lifecycle

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
1.6 KB
---
name: iOS App Lifecycle
description: Standards for AppDelegate, SceneDelegate, Deep Linking, and Background Tasks.
metadata:
  labels: [ios, lifecycle, scenedelegate, background-tasks]
  triggers:
    files: ['AppDelegate.swift', 'SceneDelegate.swift']
    keywords:
      [
        didFinishLaunchingWithOptions,
        willConnectTo,
        backgroundTask,
        Shortcut,
        UserActivity,
      ]
---

# iOS App Lifecycle Standards

## **Priority: P0**

## Implementation Guidelines

### App & Scene Delegate

- **SceneDelegate**: Use for UI windows and scene-specific state in iOS 13+.
- **AppDelegate**: Focus on app-wide setup (DI, Analytics, Push notification registration).
- **Slim Delegates**: Move initialization logic to dedicated `Bootstrapper` or `AppCoordinator`.

### Deep Linking

- **Universal Links**: Prefer over custom URL schemes. Handle via `scene(_:continue:userActivity:)`.
- **Handling logic**: Routing should be handled by the Root Coordinator to navigate to specific screens.

### Background Tasks

- **Background Fetch**: Use `BGTaskScheduler` for periodically refreshing data.
- **Expiration**: Handle `expirationHandler` to avoid app kill by the system.

## Anti-Patterns

- **Fat AppDelegate**: `**No complex logic in didFinishLaunching**: Use a Bootstrapper service.`
- **Direct UI in AppDelegate**: `**No UIWindow setup in AppDelegate**: Use SceneDelegate for iOS 13+.`
- **Blocking Launch**: `**No synchronous network calls in launch**: Move to background thread or defer.`

## References

- [Lifecycle & Background Tasks](references/implementation.md)

Overview

This skill defines iOS app lifecycle standards for AppDelegate, SceneDelegate, deep linking, and background tasks. It codifies where to place initialization, routing, and background work so agents produce consistent, maintainable iOS code. The guidance targets iOS 13+ with scene support and modern background APIs.

How this skill works

The skill inspects app entry points and recommends moving heavy initialization out of AppDelegate into a Bootstrapper or AppCoordinator. It enforces SceneDelegate for window and UI state, Universal Links for deep linking, and BGTaskScheduler for periodic background work. It also flags anti-patterns like synchronous network calls or direct UI setup in AppDelegate.

When to use it

  • When generating or reviewing iOS app startup code for iOS 13+
  • When implementing deep linking and routing to app screens
  • When scheduling periodic background fetches and long-running tasks
  • When enforcing clean separation of concerns between app-wide and scene-specific logic
  • When converting legacy AppDelegate-heavy projects to modern patterns

Best practices

  • Keep AppDelegate slim: limit to DI, analytics, push registration, and hand off orchestration to a Bootstrapper or AppCoordinator.
  • Use SceneDelegate for UIWindow and scene-specific state on iOS 13 and later; avoid creating UI in AppDelegate.
  • Prefer Universal Links over custom URL schemes; handle incoming NSUserActivity in scene(_:continue:userActivity:) and delegate routing to the Root Coordinator.
  • Use BGTaskScheduler for background refresh and processing; register tasks and provide robust expirationHandler implementations.
  • Avoid blocking work during launch: do not perform synchronous network calls in didFinishLaunching; defer work or run on background threads.

Example use cases

  • Generating a new app template that wires AppDelegate to a Bootstrapper and provides a SceneDelegate stub for UI setup.
  • Implementing deep link handling that routes Universal Links through a Root Coordinator to specific view controllers.
  • Migrating a legacy project by removing UI creation from AppDelegate and moving it into SceneDelegate or an AppCoordinator.
  • Scheduling periodic data refresh using BGTaskScheduler with proper registration and expiration handling.
  • Linting code to detect heavy logic in didFinishLaunching or synchronous network calls during startup.

FAQ

Should I always use SceneDelegate?

For iOS 13 and later, prefer SceneDelegate for per-window UI and scene state. If supporting only iOS 12 or earlier, handle UI in AppDelegate, but aim to migrate when dropping legacy OS targets.

When are Universal Links not feasible?

Use Universal Links when possible. Custom URL schemes may be needed for legacy integrations or when Apple App Site Association cannot be configured, but they are less secure and less seamless.