Pocket How
System features

Live Activities and the Dynamic Island: ActivityKit layouts, push updates, limits

iOS 17+, iPadOS 17+. Intermediate. By Cihat Salik, .

Short answer

Define ActivityAttributes with a small ContentState, return an ActivityConfiguration with Lock Screen and Dynamic Island layouts from your widget extension, and start it with Activity.request. Update it from the app or from your server with ActivityKit pushes; push-to-start needs iOS 17.2. Keep data under 4 KB and expect the system to end the activity after eight hours.

The problem

A Live Activity is a small, constantly visible view of something happening right now: a delivery, a match, a timer, a ride. It looks like a widget and lives in your widget extension, but it does not use timelines, cannot touch the network, and has hard size and time limits. Most bugs come from treating it like a widget (expecting it to fetch its own data) or like a notification (expecting every push to arrive). The design that holds up is a tiny content state, updated from the app while it runs and from your server when it does not.

Set up the target

Apple’s Displaying live data with Live Activities lists the steps:

  1. Add a widget extension and tick “Include Live Activity”, or add an ActivityConfiguration to your existing extension and widget bundle.
  2. Set NSSupportsLiveActivities to YES in the app target’s Info.plist (“Supports Live Activities” in the Info tab).
  3. Define an ActivityAttributes type and add it to both the app and the extension targets.

Matteo Altobello’s Create with Swift walkthrough uses a clean split worth copying: the attributes file in a shared group with both target memberships, start and update logic in an observable model in the app, and only the views in the extension.

Model static and dynamic data

ActivityAttributes holds what never changes during the activity. Its nested ContentState holds what does. The ContentState is what you send in every update, so keep it small and flat.

import ActivityKit
import Foundation

struct DeliveryAttributes: ActivityAttributes {
    struct ContentState: Codable, Hashable {
        var stage: Stage
        var eta: ClosedRange<Date>
    }

    enum Stage: String, Codable, Hashable {
        case preparing, onTheWay, arriving, delivered
    }

    let orderNumber: String
    let restaurant: String
}

Apple sets the budget: static and dynamic data combined cannot exceed 4 KB, for both local updates and push payloads. Store identifiers and short strings, never images or long text. Images go in the extension’s asset catalog, and Apple warns that an image larger than the presentation size can make the activity fail to start.

Build every presentation

You must provide all presentations; the system picks which to show on each device.

  • Lock Screen also appears as a banner on devices without a Dynamic Island, and scaled up in StandBy.
  • Compact is a leading and a trailing view either side of the camera, used when yours is the only activity.
  • Minimal is a single small view, used when several apps have activities.
  • Expanded appears on touch and hold, and briefly for alerting updates. It has leading, trailing, center and bottom regions.
import ActivityKit
import SwiftUI
import WidgetKit

struct DeliveryLiveActivity: Widget {
    var body: some WidgetConfiguration {
        ActivityConfiguration(for: DeliveryAttributes.self) { context in
            DeliveryLockScreenView(context: context)
                .activityBackgroundTint(Color.orange.opacity(0.2))
                .activitySystemActionForegroundColor(.orange)
        } dynamicIsland: { context in
            DynamicIsland {
                DynamicIslandExpandedRegion(.leading) {
                    Label(context.attributes.restaurant, systemImage: "bag.fill")
                        .font(.caption)
                }
                DynamicIslandExpandedRegion(.trailing) {
                    Text(timerInterval: context.state.eta, countsDown: true)
                        .monospacedDigit()
                        .frame(width: 56)
                }
                DynamicIslandExpandedRegion(.bottom) {
                    StageProgressView(stage: context.state.stage)
                }
            } compactLeading: {
                Image(systemName: "bag.fill")
                    .foregroundStyle(.orange)
            } compactTrailing: {
                Text(timerInterval: context.state.eta, countsDown: true)
                    .monospacedDigit()
                    .frame(width: 44)
            } minimal: {
                Image(systemName: "bag.fill")
                    .foregroundStyle(.orange)
            }
            .keylineTint(.orange)
            .widgetURL(URL(string: "food://order/\(context.attributes.orderNumber)"))
        }
    }
}

DeliveryLockScreenView and StageProgressView are ordinary SwiftUI views and are left out. Note Text(timerInterval:countsDown:): it counts down on its own, so you do not need an update every second.

Two details from Apple’s custom views guide correct a common misreading. The Dynamic Island background is always black and cannot be changed; keylineTint(_:) only tints its border in Dark Mode. Majid Jabrayilov’s otherwise excellent Mastering Dynamic Island in SwiftUI describes keylineTint as changing the background, which is not what Apple documents or what you will see. His advice on priority for expanded regions and .dynamicIsland(verticalPlacement: .belowIfTooWide) for wide leading content still holds.

Also from Apple: the system may truncate a Lock Screen presentation taller than 160 points, it ignores your animation modifiers in favor of its own timing, and compact views can render with reduced width (two activities on newer Pro iPhones, landscape, iPhone Duo). Check @Environment(\.isDynamicIslandLimitedInWidth) and shorten text when it is true.

Start, update and end from the app

Check that Live Activities are enabled, then request one while the app is in the foreground. Pass pushType: .token if your server will send updates.

import ActivityKit
import Observation

@MainActor
@Observable
final class DeliveryTracker {
    private(set) var activity: Activity<DeliveryAttributes>?
    private(set) var lastError: String?

    func start(order: String, restaurant: String, eta: ClosedRange<Date>) {
        guard ActivityAuthorizationInfo().areActivitiesEnabled else {
            lastError = "Live Activities are turned off for this app in Settings."
            return
        }
        let attributes = DeliveryAttributes(orderNumber: order, restaurant: restaurant)
        let state = DeliveryAttributes.ContentState(stage: .preparing, eta: eta)
        do {
            let activity = try Activity.request(
                attributes: attributes,
                content: ActivityContent(state: state, staleDate: eta.upperBound),
                pushType: .token
            )
            self.activity = activity
            observeToken(of: activity)
        } catch {
            lastError = error.localizedDescription
        }
    }

    func advance(to stage: DeliveryAttributes.Stage, eta: ClosedRange<Date>) async {
        guard let activity else { return }
        let state = DeliveryAttributes.ContentState(stage: stage, eta: eta)
        let alert = stage == .arriving
            ? AlertConfiguration(title: "Almost there", body: "Your order is arriving.", sound: .default)
            : nil
        await activity.update(
            ActivityContent(state: state, staleDate: eta.upperBound, relevanceScore: 50),
            alertConfiguration: alert
        )
    }

    func finish() async {
        guard let activity else { return }
        let final = DeliveryAttributes.ContentState(stage: .delivered, eta: .now ... .now)
        await activity.end(ActivityContent(state: final, staleDate: nil), dismissalPolicy: .default)
        self.activity = nil
    }

    private func observeToken(of activity: Activity<DeliveryAttributes>) {
        Task {
            for await token in activity.pushTokenUpdates {
                let hex = token.map { String(format: "%02x", $0) }.joined()
                try? await PushRegistry.upload(activityToken: hex, activityID: activity.id)
            }
        }
    }
}

PushRegistry stands for your networking layer; in production, surface its errors rather than dropping them with try?. The push token arrives asynchronously and can change during the activity, which is why you observe pushTokenUpdates instead of reading pushToken right after the request. When a new token arrives, invalidate the old one on your server.

Always end with a final content state. With the .default dismissal policy the ended activity stays on the Lock Screen for up to four hours, so it must show the final result. .immediate removes it, and .after(_:) takes a date inside that four-hour window.

The staleDate is cheap insurance. When it passes, context.isStale becomes true and you can show “Updating…” instead of a wrong ETA.

Start without the foreground

There are three ways around the foreground rule:

  • A LiveActivityIntent (iOS 17) can call Activity.request from perform(), so a control or a Shortcut can start an activity while your app is in the background. Apple gives a Control Center control as the example.
  • On iOS 26, request(attributes:content:pushType:style:alertConfiguration:start:) schedules an activity for a later date. Apple’s reference page says you must pass an AlertConfiguration, the state is .pending until it starts, and scheduled activities count toward the system’s limit.
  • Push-to-start, covered next.

Update and start with push notifications

Apple’s ActivityKit push guide is the reference. Every request to APNs needs:

  • apns-push-type: liveactivity
  • apns-topic: <bundle ID>.push-type.liveactivity
  • apns-priority: 5 or 10

The aps dictionary carries timestamp, event (update or end), and content-state matching your ContentState property names exactly. ActivityKit decodes with default JSON strategies, so a custom date or key encoding on the server breaks every update.

curl --http2 \
  --header "apns-topic: com.example.food.push-type.liveactivity" \
  --header "apns-push-type: liveactivity" \
  --header "apns-priority: 10" \
  --header "authorization: bearer $AUTH_TOKEN" \
  --data '{"aps":{"timestamp":'"$(date +%s)"',"event":"update","content-state":{"stage":"onTheWay","eta":[786000000,786001200]}}}' \
  "https://api.sandbox.push.apple.com/3/device/$ACTIVITY_TOKEN"

A ClosedRange<Date> encodes as a two-element array, and each date as seconds since 1 January 2001, which is what the numbers above are. Run your own ContentState through JSONEncoder once and paste the output into your server tests; that catches every mismatch before it reaches a device.

Priority and frequency

Priority 10 delivers immediately and counts against an hourly budget. Priority 5 does not count, and Apple recommends trying it first and mixing the two: low priority for routine progress, high for what the person must see now. If your activity truly needs many updates per minute, such as live sports, add NSSupportsLiveActivitiesFrequentUpdates to the Info.plist. People can turn frequent updates off in Settings, so read ActivityAuthorizationInfo().frequentPushesEnabled (iOS 16.2) and tell your server.

Push-to-start

Since iOS 17.2 your server can start an activity. Observe Activity<DeliveryAttributes>.pushToStartTokenUpdates early in the app’s life, without starting anything, and send that token to your server.

import ActivityKit

enum PushToStart {
    static func observe() {
        guard #available(iOS 17.2, *) else { return }
        Task {
            for await token in Activity<DeliveryAttributes>.pushToStartTokenUpdates {
                let hex = token.map { String(format: "%02x", $0) }.joined()
                try? await PushRegistry.upload(pushToStartToken: hex)
            }
        }
    }
}

A start payload sets event to start, includes attributes-type (your Swift type name), attributes, content-state, and an alert, which is required so the person is not surprised. The system starts the activity, wakes your app with background time, and hands you an update token through pushTokenUpdates. On iOS 18 and later you can add "input-push-token": 1 to request that token explicitly, or input-push-channel to subscribe the new activity to a broadcast channel.

Broadcast channels

For one event followed by many people, iOS 18 adds channels: you create a channel on APNs, the app requests the activity with pushType: .channel(channelID), and one push to the channel updates every subscriber. Broadcast capability is enabled on developer.apple.com, not in Xcode, and you cannot start an activity with a broadcast push.

Testing

Log the token, then send payloads with curl or the Push Notifications Console. Apple notes that Simulator receives ActivityKit pushes on Apple silicon or T2 Macs running macOS 13 or later. When an update vanishes, check the liveactivitiesd, apsd and chronod processes in Console.app.

Surfaces beyond the iPhone

Apple’s custom views guide describes where your activity already appears:

  • Apple Watch shows it in the Smart Stack using the compact presentation.
  • CarPlay shows it on the Home Screen using the compact presentation. Buttons and toggles do not perform actions there. The WWDC25 session What’s new in widgets introduced this with iOS 26.
  • A paired Mac shows it in the menu bar with your unchanged compact, minimal and expanded views, and clicking opens the app through iPhone Mirroring.
  • iPad shows the Lock Screen presentation.

To design for the watch and CarPlay instead of accepting the default, declare .supplementalActivityFamilies([.small]) on the configuration (iOS 18) and switch on @Environment(\.activityFamily). .medium covers the Lock Screen layout.

Apple’s documentation also lists ActivityKit for macOS 27.3, which is in beta at the time of writing. Do not plan a Mac-native Live Activity until that ships.

Buttons in a Live Activity

Live Activities accept Button and Toggle with an intent in the expanded and Lock Screen presentations, as Apple’s interactivity guide explains. Conform the intent to LiveActivityIntent so it runs in the app’s process, where it can call activity.update. Put it in the app target.

import ActivityKit
import AppIntents

struct ConfirmPickupIntent: LiveActivityIntent {
    static let title: LocalizedStringResource = "Confirm pickup"

    @Parameter(title: "Order")
    var orderNumber: String

    init() {}

    init(orderNumber: String) {
        self.orderNumber = orderNumber
    }

    func perform() async throws -> some IntentResult {
        for activity in Activity<DeliveryAttributes>.activities
        where activity.attributes.orderNumber == orderNumber {
            let state = DeliveryAttributes.ContentState(stage: .delivered, eta: .now ... .now)
            await activity.end(ActivityContent(state: state, staleDate: nil), dismissalPolicy: .immediate)
        }
        return .result()
    }
}

Limits to design around

  • Eight hours active. After that the system ends the activity and removes it from the Dynamic Island. It can stay on the Lock Screen for up to four more hours, so twelve hours is the total.
  • 4 KB of combined static and dynamic data.
  • No network, no location inside the activity’s sandbox.
  • A device-wide cap on simultaneous activities, which Apple does not publish. Catch the error from request and handle it.
  • People can remove it from the Lock Screen. That ends the activity, not the order behind it; watch activityStateUpdates for .dismissed.
  • Pushes can be lost when the device is offline. Also update from the app whenever it runs.

Checklist

Task API Minimum
Start, update, end in app Activity.request, update, end iOS 16.1
Interactive buttons LiveActivityIntent iOS 17
Server start pushToStartTokenUpdates iOS 17.2
Channels, input-push-token pushType: .channel(_:) iOS 18
Watch and CarPlay layouts supplementalActivityFamilies(_:), activityFamily iOS 18
Scheduled start request(...start:) iOS 26
Frequent updates NSSupportsLiveActivitiesFrequentUpdates iOS 16.2

Preview every presentation with #Preview(as: .dynamicIsland(.expanded), using:) and its siblings before running on a device, and test once in Always On, where the system skips animations and renders in a dark style. Use isLuminanceReduced to dim bright colors there.

Sources and further reading

Read next