Live activity generator

From gustavscirulis/snapgrid · View interactive version

Live activity generator is an AI agent skill from the GitHub repository gustavscirulis/snapgrid. Generate ActivityKit Live Activity infrastructure with Dynamic Island layouts, Lock Screen presentation, and push-to-update support. Use when adding Live Activities to an iOS app.

How to use this skill

Skill file

Live Activity Generator

Generate a complete ActivityKit Live Activity implementation with Dynamic Island layouts, Lock Screen presentation, activity lifecycle management, and push-to-update support.

When This Skill Activates

Use this skill when the user:

Pre-Generation Checks

1. Project Context Detection

2. Conflict Detection

Search for existing Live Activity code:

Glob: **/*Activity*.swift, **/*LiveActivity*.swift
Grep: "ActivityKit" or "ActivityAttributes" or "ActivityConfiguration"

If an existing widget extension is found:

If Live Activity code already exists:

3. Required Capabilities

Live Activities require:

Configuration Questions

Ask user via AskUserQuestion:

  1. What is the Live Activity for? (freeform)
  1. What data should appear on the Lock Screen? (freeform)
  1. Dynamic Island layout needs?
  1. Push-to-update support?
  1. Alert configuration when ending?

Generation Process

Step 1: Determine File Locations

Check project structure:

For the activity manager (lives in the main app target):

For the widget extension views:

Step 2: Create Core Files

Generate these files based on configuration answers:

  1. {Name}ActivityAttributes.swift -- Shared between app and widget extension
  1. {Name}LiveActivityView.swift -- Widget extension file
  1. {Name}ActivityManager.swift -- Main app target file

Step 3: Generate Code from Templates

Use the templates in templates.md and customize based on user answers:

Info.plist Required

Main App Target

<key>NSSupportsLiveActivities</key>
<true/>

<!-- Optional: for frequent push updates (iOS 16.2+) -->
<key>NSSupportsLiveActivitiesFrequentUpdates</key>
<true/>

Output Format

After generation, provide:

Files Created

Sources/LiveActivity/
├── {Name}ActivityAttributes.swift     # Shared: attributes + content state
└── {Name}ActivityManager.swift        # Main app: lifecycle management

MyAppWidgets/
├── {Name}LiveActivityView.swift       # Widget ext: all Live Activity UI
└── (update WidgetBundle if needed)

Integration Steps

1. Add the widget extension target (if not present):

2. Share the attributes file between targets:

The {Name}ActivityAttributes.swift file must be included in both the main app target and the widget extension target. Select the file in Xcode, open the File Inspector, and check both targets under "Target Membership".

3. Add Info.plist entries in the main app target:

<key>NSSupportsLiveActivities</key>
<true/>

4. Register the Live Activity configuration in the widget bundle:

@main
struct MyAppWidgets: WidgetBundle {
    var body: some Widget {
        // Existing widgets...
        MyAppLiveActivity()
    }
}

5. Start a Live Activity from your app:

let attributes = DeliveryActivityAttributes(
    orderNumber: "1234",
    restaurantName: "Pizza Place"
)

let initialState = DeliveryActivityAttributes.ContentState(
    status: .preparing,
    estimatedDelivery: Date().addingTimeInterval(30 * 60),
    driverName: nil
)

let manager = LiveActivityManager()
try await manager.startActivity(attributes: attributes, state: initialState)

6. Update the activity when state changes:

let updatedState = DeliveryActivityAttributes.ContentState(
    status: .enRoute,
    estimatedDelivery: Date().addingTimeInterval(15 * 60),
    driverName: "Alex"
)

await manager.updateActivity(state: updatedState)

7. End the activity when complete:

let finalState = DeliveryActivityAttributes.ContentState(
    status: .delivered,
    estimatedDelivery: Date(),
    driverName: "Alex"
)

await manager.endActivity(state: finalState, dismissalPolicy: .default)

Push-to-Update Setup (if enabled)

1. Observe push tokens:

The generated {Name}ActivityManager automatically observes push token updates. Send the token to your server when it changes.

2. Server-side APNs request:

curl -v \
  --header "authorization: bearer $JWT_TOKEN" \
  --header "apns-topic: com.yourcompany.yourapp.push-type.liveactivity" \
  --header "apns-push-type: liveactivity" \
  --http2 \
  --data '{"aps":{"timestamp":1234567890,"event":"update","content-state":{"status":"enRoute","estimatedDelivery":1234568000,"driverName":"Alex"}}}' \
  https://api.push.apple.com/3/device/$PUSH_TOKEN

Note: The apns-topic must be your app bundle ID with .push-type.liveactivity appended.

3. Ending via push:

{
  "aps": {
    "timestamp": 1234567890,
    "event": "end",
    "dismissal-date": 1234568000,
    "content-state": {
      "status": "delivered",
      "estimatedDelivery": 1234567890,
      "driverName": "Alex"
    }
  }
}

Testing Instructions

  1. Device required: Live Activities and Dynamic Island cannot be tested in Simulator (as of Xcode 15). Use a physical device with iOS 16.1+.
  2. Dynamic Island: Requires iPhone 14 Pro or later (devices with the Dynamic Island hardware).
  3. Push-to-update testing: Use a tool like apnspush or curl with an APNs auth key (.p8 file) to send test payloads.
  4. Debug tips:

Common Patterns

Delivery Tracking

Static: order number, restaurant name

Dynamic: status enum, ETA, driver name

Sports Score

Static: home team, away team, sport type

Dynamic: home score, away score, period/quarter, game clock

Workout / Timer

Static: workout type, goal

Dynamic: elapsed time, calories, heart rate, distance

Ride-Sharing

Static: pickup location, destination

Dynamic: driver name, ETA, vehicle info, status

Gotchas and Limits

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.