JSPM

@cliffhelsel/capacitor-live-activity

7.0.1-cliff.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q31639F
  • License MIT

A Capacitor plugin for managing iOS Live Activities using ActivityKit and Swift.

Package Exports

  • @cliffhelsel/capacitor-live-activity
  • @cliffhelsel/capacitor-live-activity/dist/esm/index.js
  • @cliffhelsel/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 (@cliffhelsel/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

npm bundle size License: MIT Platforms Capacitor

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

📦 Install

npm install capacitor-live-activity
npx cap sync

[!NOTE] 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.

🧩 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

  1. Open your app’s iOS project in Xcode.
  2. Go to File > New > Target…
  3. Choose Widget Extension.
  4. Name it e.g. LiveActivityWidget.
  5. Check the box “Include Live Activity”.
  6. 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:

  1. Open Xcode and go to the File Navigator.
  2. Expand Pods > CapacitorLiveActivity > Shared.
  3. Copy GenericAttributes.swift to Widget Extension Target, e.g. LiveActivityWidget
  4. 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

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).

📱 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(...)

startActivity(options: StartActivityOptions) => Promise<void>

Starts a new Live Activity on iOS using the provided options.

Param Type
options StartActivityOptions

Since: 0.0.1


startObservingPushToStartToken()

startObservingPushToStartToken() => Promise<void>

addListener('pushToStartToken', ...)

addListener(eventName: 'pushToStartToken', listenerFunc: (data: { token: string; }) => void) => Promise<PluginListenerHandle>
Param Type
eventName 'pushToStartToken'
listenerFunc (data: { token: string; }) => void

Returns: Promise<PluginListenerHandle>


updateActivity(...)

updateActivity(options: UpdateActivityOptions) => Promise<void>

Updates the currently active Live Activity.

Param Type
options UpdateActivityOptions

Since: 0.0.1


endActivity(...)

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()

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(...)

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(...)

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


Interfaces

StartActivityOptions

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.

PluginListenerHandle

Prop Type
remove () => Promise<void>

UpdateActivityOptions

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.

AlertConfiguration

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".

EndActivityOptions

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.

LiveActivityState

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.

Type Aliases

Record

Construct a type with a set of properties K of type T

{ [P in K]: T; }