Live Activities for the Apple SDK

Integrate Live Activities into your iOS app to display real-time updates on the Lock Screen and Dynamic Island. AXP

For information about Live Activities, including overview, use cases, and how to send Live Activities via the Push API, see the iOS Live Activities user guide.

App Setup

To support Live Activities, you must call restoreLiveActivityTracking once after takeOff with all the Live Activity types that you might track with Airship. This allows Airship to resume tracking any previously tracked activities across app inits and to automatically track the pushToStartToken that allows starting activities through a push notification.

Restore Live Activity tracking

Airship.takeOff(config, launchOptions: launchOptions)

Airship.channel.restoreLiveActivityTracking { restorer in
    await restorer.restore(forType: Activity<SportsActivityAttributes>.self)
    await restorer.restore(forType: Activity<SomeOtherAttributes>.self)
}
 Note

Live Activities are not supported in Objective-C. Use Swift for Live Activity implementation.

After the restore call above, Airship will track the pushToStartTokens for the activity’s attribute types. You can then start a Live Activity through a push notification. Starting a Live Activity does not automatically track it. Instead, the app will be woken up and you must call through to Airship with the activity instance and the name.

Watching for Live Activities

There is no entry point into the app when it is started for a Live Activity being created. Instead, you need to query Live Activities on init and when a pushToStartToken update is received to track them through Airship. Airship provides an extension Activity<T>.airshipWatchActivities(activityBlock:) that can be used to do this for you.

In this example, we assume the gameID on our SportsActivityAttributes will be used to send updates through Airship after it is created:

Watch Live Activities

Airship.channel.restoreLiveActivityTracking { restorer in
    await restorer.restore(forType: Activity<SportsActivityAttributes>.self)
}

Activity<SportsActivityAttributes>.airshipWatchActivities { activity in
    Airship.channel.trackLiveActivity(activity, name: activity.attributes.gameID)
}
 Note

Live Activities are not supported in Objective-C. Use Swift for Live Activity implementation.

Starting Live Activities

To start a Live Activity from the app, make sure to set the pushType to .token. After it is started, immediately track it with Airship.channel.trackLiveActivity(_:name:).

Start a Live Activity

let activity = try Activity.request(
    attributes: attributes,
    content: content,
    pushType: .token
)

Airship.channel.trackLiveActivity(
    activity,
    name: attributes.gameID
)
 Note

Live Activities are not supported in Objective-C. Use Swift for Live Activity implementation.

Updating Live Activities

To update a Live Activity, use the standard ActivityKit APIs. First find the Activity instance then call update on it:

Update a Live Activity

guard
    let activity = Activity<SportsActivityAttributes>.activities.first(where: { $0.id == "sports-game-123" })
else {
    // not found
    return
}
activity.update(contentUpdate)
 Note

Live Activities are not supported in Objective-C. Use Swift for Live Activity implementation.

Ending Live Activities

To end a Live Activity, use the standard ActivityKit APIs. First find the Activity instance then call end on it with a dismissal policy:

End a Live Activity

guard
    let activity = Activity<SportsActivityAttributes>.activities.first(where: { $0.id == "sports-game-123" })
else {
    // not found
    return
}

activity.end(contentUpdate, dismissalPolicy: .default)
 Note

Live Activities are not supported in Objective-C. Use Swift for Live Activity implementation.