Package Exports
- capacitor-live-activity
- capacitor-live-activity/dist/esm/index.js
- capacitor-live-activity/dist/plugin.cjs.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (capacitor-live-activity) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
📡 capacitor-live-activity
A Capacitor plugin for managing iOS Live Activities using ActivityKit and Swift.
[!TIP] 🚀 Looking for a ready-to-run demo? → Try the Example App
🧭 Table of contents
- 📡 capacitor-live-activity
- 🧭 Table of contents
- 📦 Install
- 🧩 Widget Setup (Required)
- 🧠 Platform behavior
- 📱 Example App
- 🛠 API
- startActivity(...)
- startActivityWithPush(...)
- updateActivity(...)
- endActivity(...)
- isAvailable()
- isRunning(...)
- getCurrentActivity(...)
- listActivities()
- observePushToStartToken()
- addListener('liveActivityPushToken', ...)
- addListener('liveActivityPushToStartToken', ...)
- addListener('liveActivityUpdate', ...)
- Interfaces
- Type Aliases
📦 Install
npm install capacitor-live-activity
npx cap sync[!NOTE] This plugin requires iOS 16.2+ to work properly due to
ActivityKitAPI 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.
🧩 Widget Setup (Required)
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.
1. Add a Widget Extension in Xcode
- 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.
2. Configure the Widget (Example)
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("🎯")
}
}
}
}3. Add GenericAttributes.swift to your Widget Target
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
To make it available in your widget extension:
- 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"
Why is this needed?
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.
4. Add Capability
Go to your main app target → Signing & Capabilities tab and add:
- Background Modes → Background fetch
- Go to your app target → Signing & Capabilities:
- ✅ Push Notifications
- ✅ Live Activities
5. Ensure Inclusion in Build
- In your App target’s Info.plist, ensure:
<key>NSSupportsLiveActivities</key>
<true/>- Clean and rebuild the project (Cmd + Shift + K, then Cmd + B).
🧠 Platform behavior
- iOS 16.2+: Live Activities (local start/update/end)
- iOS 17.2+: Remote start via push (push-to-start) and per-activity push updates
- Real device required (no Simulator)
- For remote flows, test with the app in background/terminated
📱 Example App
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
🛠 API
startActivity(...)startActivityWithPush(...)updateActivity(...)endActivity(...)isAvailable()isRunning(...)getCurrentActivity(...)listActivities()observePushToStartToken()addListener('liveActivityPushToken', ...)addListener('liveActivityPushToStartToken', ...)addListener('liveActivityUpdate', ...)- Interfaces
- Type Aliases
startActivity(...)
startActivity(options: StartActivityOptions) => Promise<void>Start a new Live Activity with local (on-device) ActivityKit.
| Param | Type |
|---|---|
options |
StartActivityOptions |
Since: 0.0.1
startActivityWithPush(...)
startActivityWithPush(options: StartActivityOptions) => Promise<{ activityId: string; }>Start a new Live Activity locally with push support (pushType: .token).
The per-activity APNs/FCM live-activity token will be emitted via
the "liveActivityPushToken" event shortly after starting.
| Param | Type |
|---|---|
options |
StartActivityOptions |
Returns: Promise<{ activityId: string; }>
Since: 7.1.0
updateActivity(...)
updateActivity(options: UpdateActivityOptions) => Promise<void>Update an existing Live Activity (identified by your logical id).
| Param | Type |
|---|---|
options |
UpdateActivityOptions |
Since: 0.0.1
endActivity(...)
endActivity(options: EndActivityOptions) => Promise<void>End an existing Live Activity (identified by your logical id).
Optionally provide a final state and a dismissal policy.
| Param | Type |
|---|---|
options |
EndActivityOptions |
Since: 0.0.1
isAvailable()
isAvailable() => Promise<{ value: boolean; }>Return whether Live Activities are enabled and allowed on this device.
Note: This method resolves to { value: boolean } to match native.
Returns: Promise<{ value: boolean; }>
Since: 0.0.1
isRunning(...)
isRunning(options: { id: string; }) => Promise<{ value: boolean; }>Return whether a Live Activity with the given logical id is currently running.
Note: This method resolves to { value: boolean } to match native.
| Param | Type |
|---|---|
options |
{ id: string; } |
Returns: Promise<{ value: boolean; }>
Since: 0.0.1
getCurrentActivity(...)
getCurrentActivity(options?: { id?: string | undefined; } | undefined) => Promise<LiveActivityState | undefined>Get the current Live Activity state.
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
listActivities()
listActivities() => Promise<ListActivitiesResult>List known activities (ActivityKit active/stale/pending etc.)
for the shared GenericAttributes type.
Useful to discover activities that were started via push once the process becomes aware of them.
Returns: Promise<ListActivitiesResult>
Since: 7.1.0
observePushToStartToken()
observePushToStartToken() => Promise<void>iOS 17.2+: begin streaming the global push-to-start token.
The token will be emitted via "liveActivityPushToStartToken".
Since: 7.1.0
addListener('liveActivityPushToken', ...)
addListener(eventName: 'liveActivityPushToken', listenerFunc: (event: PushTokenEvent) => void) => Promise<PluginListenerHandle>Emitted when a per-activity live-activity push token becomes available
after calling startActivityWithPush.
| Param | Type |
|---|---|
eventName |
'liveActivityPushToken' |
listenerFunc |
(event: PushTokenEvent) => void |
Returns: Promise<PluginListenerHandle>
Since: 7.1.0
addListener('liveActivityPushToStartToken', ...)
addListener(eventName: 'liveActivityPushToStartToken', listenerFunc: (event: PushToStartTokenEvent) => void) => Promise<PluginListenerHandle>Emitted when a global push-to-start token is available (iOS 17.2+).
| Param | Type |
|---|---|
eventName |
'liveActivityPushToStartToken' |
listenerFunc |
(event: PushToStartTokenEvent) => void |
Returns: Promise<PluginListenerHandle>
Since: 7.1.0
addListener('liveActivityUpdate', ...)
addListener(eventName: 'liveActivityUpdate', listenerFunc: (event: ActivityUpdateEvent) => void) => Promise<PluginListenerHandle>Emitted when the lifecycle of a Live Activity changes (e.g. active → stale).
| Param | Type |
|---|---|
eventName |
'liveActivityUpdate' |
listenerFunc |
(event: ActivityUpdateEvent) => void |
Returns: Promise<PluginListenerHandle>
Since: 7.1.0
Interfaces
StartActivityOptions
Options for starting a Live Activity.
| Prop | Type | Description |
|---|---|---|
id |
string |
Logical identifier you use to reference the activity. |
attributes |
Record<string, string> |
Immutable attributes for the activity. |
contentState |
Record<string, string> |
Initial dynamic content state. |
timestamp |
number |
Optional UNIX timestamp when the activity started. |
UpdateActivityOptions
Options for updating a Live Activity.
| Prop | Type | Description |
|---|---|---|
id |
string |
Logical identifier of the activity to update. |
contentState |
Record<string, string> |
Updated dynamic content state. |
alert |
AlertConfiguration |
Optional alert configuration to show a notification banner or Apple Watch alert. |
timestamp |
number |
Optional UNIX timestamp for the update. |
AlertConfiguration
Alert configuration shown for certain updates.
| 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". |
EndActivityOptions
Options for ending a Live Activity.
| Prop | Type | Description |
|---|---|---|
id |
string |
Logical identifier of the activity to end. |
contentState |
Record<string, string> |
Final dynamic content state to render before dismissal. |
timestamp |
number |
Optional UNIX timestamp for the end event. |
dismissalDate |
number |
Optional future dismissal time (UNIX). If omitted, the system default dismissal policy applies. |
LiveActivityState
Represents the state of a Live Activity returned by the plugin.
| Prop | Type | Description |
|---|---|---|
id |
string |
System activity identifier (Activity.id). |
values |
Record<string, string> |
Current dynamic values. |
isStale |
boolean |
Whether the activity is stale. |
isEnded |
boolean |
Whether the activity has ended. |
startedAt |
string |
ISO string of when the activity started (if provided). |
ListActivitiesResult
Result of listing activities.
| Prop | Type |
|---|---|
items |
Array<{ /** Your logical ID (attributes.id). / id: string; /* System activity identifier (Activity.id). / activityId: string; /* ActivityKit state as a string ("active" | "stale" | "pending" | "ended" | "dismissed"). */ state: string; }> |
Array
| Prop | Type | Description |
|---|---|---|
length |
number |
Gets or sets the length of the array. This is a number one higher than the highest index in the array. |
| Method | Signature | Description |
|---|---|---|
| toString | () => string | Returns a string representation of an array. |
| toLocaleString | () => string | Returns a string representation of an array. The elements are converted to string using their toLocalString methods. |
| pop | () => T | undefined | Removes the last element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. |
| push | (...items: T[]) => number | Appends new elements to the end of an array, and returns the new length of the array. |
| concat | (...items: ConcatArray<T>[]) => T[] | Combines two or more arrays. This method returns a new array without modifying any existing arrays. |
| concat | (...items: (T | ConcatArray<T>)[]) => T[] | Combines two or more arrays. This method returns a new array without modifying any existing arrays. |
| join | (separator?: string | undefined) => string | Adds all the elements of an array into a string, separated by the specified separator string. |
| reverse | () => T[] | Reverses the elements in an array in place. This method mutates the array and returns a reference to the same array. |
| shift | () => T | undefined | Removes the first element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. |
| slice | (start?: number | undefined, end?: number | undefined) => T[] | Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. For example, -2 refers to the second to last element of the array. |
| sort | (compareFn?: ((a: T, b: T) => number) | undefined) => this | Sorts an array in place. This method mutates the array and returns a reference to the same array. |
| splice | (start: number, deleteCount?: number | undefined) => T[] | Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. |
| splice | (start: number, deleteCount: number, ...items: T[]) => T[] | Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. |
| unshift | (...items: T[]) => number | Inserts new elements at the start of an array, and returns the new length of the array. |
| indexOf | (searchElement: T, fromIndex?: number | undefined) => number | Returns the index of the first occurrence of a value in an array, or -1 if it is not present. |
| lastIndexOf | (searchElement: T, fromIndex?: number | undefined) => number | Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present. |
| every | <S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any) => this is S[] | Determines whether all the members of an array satisfy the specified test. |
| every | (predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any) => boolean | Determines whether all the members of an array satisfy the specified test. |
| some | (predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any) => boolean | Determines whether the specified callback function returns true for any element of an array. |
| forEach | (callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any) => void | Performs the specified action for each element in an array. |
| map | <U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any) => U[] | Calls a defined callback function on each element of an array, and returns an array that contains the results. |
| filter | <S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any) => S[] | Returns the elements of an array that meet the condition specified in a callback function. |
| filter | (predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any) => T[] | Returns the elements of an array that meet the condition specified in a callback function. |
| reduce | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T) => T | Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. |
| reduce | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T) => T | |
| reduce | <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U) => U | Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. |
| reduceRight | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T) => T | Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. |
| reduceRight | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T) => T | |
| reduceRight | <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U) => U | Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. |
ConcatArray
| Prop | Type |
|---|---|
length |
number |
| Method | Signature |
|---|---|
| join | (separator?: string | undefined) => string |
| slice | (start?: number | undefined, end?: number | undefined) => T[] |
PluginListenerHandle
| Prop | Type |
|---|---|
remove |
() => Promise<void> |
PushTokenEvent
Event payload for per-activity live-activity push tokens.
| Prop | Type | Description |
|---|---|---|
id |
string |
Your logical ID (the one you passed to start). |
activityId |
string |
System activity identifier (Activity.id). |
token |
string |
Hex-encoded APNs/FCM live activity token for this activity. |
PushToStartTokenEvent
Event payload for the global push-to-start token (iOS 17.2+).
| Prop | Type | Description |
|---|---|---|
token |
string |
Hex-encoded APNs/FCM push-to-start token (iOS 17.2+). |
ActivityUpdateEvent
Event payload for activity lifecycle updates.
| Prop | Type | Description |
|---|---|---|
id |
string |
Your logical ID (attributes.id). |
activityId |
string |
System activity identifier (Activity.id). |
state |
string |
ActivityKit state as a string. |
Type Aliases
Record
Construct a type with a set of properties K of type T
{
[P in K]: T;
}