A Capacitor plugin for managing iOS Live Activities using ActivityKit and Swift.
Tip
🚀 Looking for a ready-to-run demo? → Try the Example App
npm install capacitor-live-activity
npx cap syncNote
This plugin requires iOS 16.2+ to work properly due to ActivityKit API usage.
Important
This plugin requires a Live Activity widget extension to be present and configured in your Xcode project.
Without a widget, Live Activities will not appear on the lock screen or Dynamic Island.
To use Live Activities, your app must include a widget extension that defines the UI for the Live Activity using ActivityKit. Without this, the Live Activity will not appear on the Lock Screen or Dynamic Island.
- Open your app’s iOS project in Xcode.
- Go to File > New > Target…
- Choose Widget Extension.
- Name it e.g. LiveActivityWidget.
- Check the box “Include Live Activity”.
- Finish and wait for Xcode to generate the files.
Make sure the widget uses the same attribute type as the plugin (e.g. GenericAttributes.swift):
import ActivityKit
import WidgetKit
import SwiftUI
struct LiveActivityWidgetLiveActivity: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(for: GenericAttributes.self) { context in
// Lock Screen UI
VStack {
Text(context.state.values["title"] ?? "⏱")
Text(context.state.values["status"] ?? "-")
}
} dynamicIsland: { context in
DynamicIsland {
DynamicIslandExpandedRegion(.leading) {
Text(context.state.values["title"] ?? "")
}
DynamicIslandExpandedRegion(.trailing) {
Text(context.state.values["status"] ?? "")
}
DynamicIslandExpandedRegion(.bottom) {
Text(context.state.values["message"] ?? "")
}
} compactLeading: {
Text("🔔")
} compactTrailing: {
Text(context.state.values["status"] ?? "")
} minimal: {
Text("🎯")
}
}
}
}To support Live Activities with dynamic values, this plugin uses a shared Swift struct called GenericAttributes.
By default, it’s located under: Pods > CapacitorLiveActivity > LiveActivityPlugin > Shared > GenericAttributes.swift
- Open Xcode and go to the File Navigator.
- Expand Pods > CapacitorLiveActivity > Shared.
- Copy GenericAttributes.swift to Widget Extension Target, e.g. LiveActivityWidget
- Make sure to select "Copy files to destination"
Xcode doesn’t automatically include files from a CocoaPods plugin into your widget target. Without this step, your widget won’t compile because it cannot find GenericAttributes.
Go to your main app target → Signing & Capabilities tab and add:
- Background Modes → Background fetch
- In your App target’s Info.plist, ensure:
<key>NSSupportsLiveActivities</key>
<true/>- Clean and rebuild the project (Cmd + Shift + K, then Cmd + B).
This plugin includes a fully functional demo app under the example-app/ directory.
The demo is designed to run on real iOS devices and showcases multiple Live Activity types like delivery, timer, taxi, workout, and more.
- Launch and test various Live Activities interactively
- Trigger updates and alert banners
- View JSON state changes in a live log console
Note
For full instructions, see example-app/README.md
startActivity(...)updateActivity(...)endActivity(...)isAvailable()isRunning(...)getCurrentActivity(...)- Interfaces
- Type Aliases
startActivity(options: StartActivityOptions) => Promise<void>Starts a new Live Activity on iOS using the provided options.
| Param | Type |
|---|---|
options |
StartActivityOptions |
Since: 0.0.1
updateActivity(options: UpdateActivityOptions) => Promise<void>Updates the currently active Live Activity.
| Param | Type |
|---|---|
options |
UpdateActivityOptions |
Since: 0.0.1
endActivity(options: EndActivityOptions) => Promise<void>Ends the Live Activity and optionally provides a final state and dismissal policy.
| Param | Type |
|---|---|
options |
EndActivityOptions |
Since: 0.0.1
isAvailable() => Promise<boolean>Returns whether Live Activities are available on this device and allowed by the user.
Returns: Promise<boolean>
Since: 0.0.1
isRunning(options: { id: string; }) => Promise<boolean>Returns true if a Live Activity with the given ID is currently running.
| Param | Type |
|---|---|
options |
{ id: string; } |
Returns: Promise<boolean>
Since: 0.0.1
getCurrentActivity(options?: { id?: string | undefined; } | undefined) => Promise<LiveActivityState | undefined>Returns the current active Live Activity state, if any.
If an ID is provided, returns that specific activity. If no ID is given, returns the most recently started activity.
| Param | Type |
|---|---|
options |
{ id?: string; } |
Returns: Promise<LiveActivityState>
Since: 0.0.1
Options for starting a Live Activity.
| Prop | Type | Description |
|---|---|---|
id |
string |
Unique ID to identify the Live Activity. |
attributes |
Record<string, string> |
Immutable attributes that are part of the Live Activity. |
contentState |
Record<string, string> |
Initial content state (dynamic values). |
timestamp |
number |
Optional timestamp (Unix) when the Live Activity started. |
Options for updating a Live Activity.
| Prop | Type | Description |
|---|---|---|
id |
string |
ID of the Live Activity to update. |
contentState |
Record<string, string> |
Updated content state (dynamic values). |
alert |
AlertConfiguration |
Optional alert configuration to show a notification banner or Apple Watch alert. |
timestamp |
number |
Optional timestamp (Unix) when the update occurred. |
Configuration for alert notifications.
| Prop | Type | Description |
|---|---|---|
title |
string |
Optional title of the alert. |
body |
string |
Optional body text of the alert. |
sound |
string |
Optional sound file name or "default". |
Options for ending a Live Activity.
| Prop | Type | Description |
|---|---|---|
id |
string |
ID of the Live Activity to end. |
contentState |
Record<string, string> |
Final state to show before dismissal. |
timestamp |
number |
Optional timestamp (Unix) when the end occurred. |
dismissalDate |
number |
Optional dismissal time in the future (Unix). If not provided, system default applies. |
Represents an active Live Activity state.
| Prop | Type | Description |
|---|---|---|
id |
string |
The unique identifier of the activity. |
values |
Record<string, string> |
The current dynamic values of the activity. |
isStale |
boolean |
Whether the activity is stale. |
isEnded |
boolean |
Whether the activity has ended. |
startedAt |
string |
ISO string timestamp when the activity started. |
Construct a type with a set of properties K of type T
{
[P in K]: T;
}