Skip to main content

Crate liveactivity

Crate liveactivity 

Source
Expand description

Live Activities for Rust applications, behind one interface.

An application or a framework plugin talks to LiveActivity; a platform implements LiveActivityBackend. The default backends are the activitykit crate on iOS and the liveupdate crate on Android, used as they are. LiveActivity::builder connects the two sides: an application names its event sink, a platform or a framework plugin its backend, and whatever is not named is the default.

use liveactivity::{EndInput, StartInput, UpdateInput};

let live = liveactivity::LiveActivity::builder()
    .event_sink(|event: liveactivity::Event| println!("{event:?}"))
    .build()?;

let order = live
    .start(StartInput::progress("order:42", "Order 42", "Preparing", 0.1))
    .await?;
live.update(UpdateInput::progress(&order.id, 1, "Order 42", "On the way", 0.6))
    .await?;
live.end(EndInput::new(&order.id)).await?;

Re-exports§

pub use ::activitykit;
pub use ::liveupdate;

Modules§

androidapp
The default Android backend: the liveupdate engine, used as it is.
contract
The contract alone: the requests, records, layout types, errors and checks, without the service. A framework plugin re-exports this as its own types.
iosapp
The iOS backend: the commands of the contract on activitykit.
push
Pushes from the application’s server: one Message for an activity, the Targets that an application reports to its server, and the Request of each platform, checked as the device checks the call it stands for.
testkittestkit
What an implementer of the interface checks a backend with.

Structs§

Accessibility
What a node tells assistive technologies such as VoiceOver, the wire member accessibility: at least one member. label, value and hint are text of 1 to 200 code points or Bound to a value of any type, which is read as a text node shows it; a value that is missing or empty leaves its member out. On a stack, any of the three makes the stack one element that stands for its children.
ActionEvent
A tap on a button or a toggle node, or on an action of an Android content.
ActionTarget
Android’s notification styles, for the AndroidContent of a snapshot. A TimerStyle takes liveupdate’s Timer, which is liveactivity::liveupdate::Timer. A component of the application that Android delivers an action’s tap to, by its class name in any Java package; with an intent action, when one component tells its targets apart.
ActivityRecord
A template activity as the backend reports it.
Alert
An alert that comes with an update, or with a scheduled start: on iOS the device lights up, the Dynamic Island expands (or, without one, the Lock Screen presentation shows as a banner), and an Apple Watch shows the title and the body. On Android the notification alerts again with that revision, with its own title and text, where the device offers it (alert in the capabilities); elsewhere the update is silent and the record reports alert in degradedFeatures. More may come: build it with Alert::new.
AndroidContent
What Android shows for a snapshot, in Android’s own terms, in place of the projection of the layout: a progress with segments and points, metrics, the text of the status chip, icons of actions, the URL a tap opens, a clock in the header. iOS ignores it.
AndroidOptions
Options of a start that only Android reads. iOS ignores them. More may come: build it with AndroidOptions::new.
AndroidPresentation
Android’s notification styles, for the AndroidContent of a snapshot. A TimerStyle takes liveupdate’s Timer, which is liveactivity::liveupdate::Timer. Resolved Android presentation attached to a schema-v2 snapshot.
BackendContext
The event sink as a backend holds it, handed over in attach.
BigTextStyle
Android’s notification styles, for the AndroidContent of a snapshot. A TimerStyle takes liveupdate’s Timer, which is liveactivity::liveupdate::Timer. Optional BigTextStyle details.
Bound
A value key in place of a literal: { "bind": "<key>" } on the wire. The member reads the value on every render, so an update can change it. The value must be what the member takes as a literal: a color name or a hex color (never a light and dark pair), a weight name, a number in the member’s range, or a URL. An accessibility member reads a value of any type.
Builderapp
Connects a LiveActivity. Both sides of the interface meet here: an application names where its taps go, and a framework plugin or a platform names the backend. Whatever is not named is the default.
Capabilities
What the backend can do on this device. A feature is supported, unsupported or unknown, and unknown never counts as supported.
EndInput
The input of end.
Error
A failure of the contract: one of ERROR_CODES and a message.
Frame
Sizes in points. At least one member.
HandledEvent
A tap that the application’s own component took (Android): the action’s target ran it, and the component recorded it with liveupdate’s LiveUpdateActions.take. It is no Event::Action: the component acted on it.
ImageInput
The input of the write_image command.
IosCapabilities
What an iPhone runs of the features after the first Live Activities, as ActivityKit’s authorization says: an application need not try a request to learn it. Each is false on a device without Live Activities.
IosOptions
Options of a start that only iOS reads. Android ignores them: two starts that differ only in them are the same activity there. More may come: build it with IosOptions::new.
Island
Dynamic Island presentations, at least one part. A part left out draws its default.
IslandExpanded
The four regions of the expanded Dynamic Island.
IslandMargins
The margins between each presentation of the Dynamic Island and what it shows, as a style’s padding: one number for every edge or [top, leading, bottom, trailing], 0 to 64 points. At least one member.
LayoutActivityRecord
A layout activity as the native side reports it. It does not repeat the layout.
LayoutEndInput
The input of end_layout: the policy, and optionally the final content, which is checked as an update. Without it the activity ends with its last accepted values.
LayoutSnapshot
The values a layout shows. An update replaces the whole map.
LayoutStartInput
The input of start_layout: a layout tree, its styles and its first values.
LayoutUpdateInput
The input of update_layout: every value again, under a higher revision.
LiveActivityapp
Live Activities of one application, on whichever backend it was connected to.
Metric
Android’s notification styles, for the AndroidContent of a snapshot. A TimerStyle takes liveupdate’s Timer, which is liveactivity::liveupdate::Timer. One labeled metric.
MetricStyle
Android’s notification styles, for the AndroidContent of a snapshot. A TimerStyle takes liveupdate’s Timer, which is liveactivity::liveupdate::Timer. Android’s API 37 metric system style.
Node
One node of a layout tree: an element and the members every node may carry.
NotificationAction
Android’s notification styles, for the AndroidContent of a snapshot. A TimerStyle takes liveupdate’s Timer, which is liveactivity::liveupdate::Timer. One action button delivered back as an crate::ActivityEvent.
OpenedEvent
The person opened the application from the notification of an activity (Android), as the host reported it to liveupdate with the opening intent. The application receives the URL itself, from that intent.
Permissions
What the operating system and the person allow.
PresentationCapabilities
Android’s notification styles, for the AndroidContent of a snapshot. A TimerStyle takes liveupdate’s Timer, which is liveactivity::liveupdate::Timer. Fine-grained Android system-presentation support. A member that a reply leaves out is false.
ProgressPoint
Android’s notification styles, for the AndroidContent of a snapshot. A TimerStyle takes liveupdate’s Timer, which is liveactivity::liveupdate::Timer. A colored marker on a rich progress track.
ProgressSegment
Android’s notification styles, for the AndroidContent of a snapshot. A TimerStyle takes liveupdate’s Timer, which is liveactivity::liveupdate::Timer. A colored part of a rich progress track.
ProgressStyle
Android’s notification styles, for the AndroidContent of a snapshot. A TimerStyle takes liveupdate’s Timer, which is liveactivity::liveupdate::Timer. Android’s rich progress system style.
PublicVersion
Android’s notification styles, for the AndroidContent of a snapshot. A TimerStyle takes liveupdate’s Timer, which is liveactivity::liveupdate::Timer. What a secure lock screen shows instead of a private activity’s content.
PushToStartTokenEvent
The app’s push-to-start token, new or changed.
PushTokenEvent
A push token of an activity, new or changed.
PushTokens
The push tokens a backend holds since launch.
PushedEvent
What a push from the application’s server did (Android, liveupdate 0.10): liveupdate’s push path ran it while the application may not have run, and stored this. A push is taken or refused as the call it stands for.
RegionPriorities
The priority of each expanded region the layout has, a number from 0 to 100: the system gives a region with a higher one the width first. A region without one has 0. At least one member.
SamsungNowBar
Android’s notification styles, for the AndroidContent of a snapshot. A TimerStyle takes liveupdate’s Timer, which is liveactivity::liveupdate::Timer. Explicit Samsung Now Bar text mapping. SamsungNowBar::default() takes the title and the status.
ScheduledStart
A start at a later time. Until then the activity is pending: it holds its key, it can be ended, and it takes no update (CONFLICT), since it begins with the content of its start. The sink receives State with active when it begins. iOS 26 and later, and Android where liveupdate’s library begins it (android_presentation.scheduled_start); elsewhere the start is UNSUPPORTED_FEATURE.
Snapshot
The content of a template activity: a title, a status and either a progress or a timer.
StartInput
The input of start: a progress or timer activity.
StartedEvent
A layout activity that began while the application ran: one it started, or one a push started.
StateEvent
A new lifecycle state of an activity, of a template or a layout.
Style
Modifiers a node takes through its style token. At least one member; font and size exclude each other, and so do font_family and design. The Bindable members may name a value instead of a literal; the others are fixed at start.
Tap
What a tap says of itself, beside the activity and the action of an ActionEvent. Each member is absent when it is not known.
Timer
A countdown, in epoch milliseconds.
TimerStyle
Android’s notification styles, for the AndroidContent of a snapshot. A TimerStyle takes liveupdate’s Timer, which is liveactivity::liveupdate::Timer. Chronometer details for a timer presentation.
UnknownEvent
An event of a kind that this version does not know (Android): liveupdate’s library of a later version stored it, and liveupdate read what it knows of it, which is the activity. The application’s crate is older than its AAR, and what happened is in that version’s documents.
UnsupportedBackendapp
The backend of a platform without Live Activities, which is the default everywhere but on iOS and Android: the two queries answer that nothing is supported, and every other call is UNSUPPORTED_PLATFORM. An application that also runs on a desktop needs no code of its own for it.
UpdateInput
The input of update: the whole content again, under a higher revision.
UpdatedEvent
Content that a push delivered to a layout activity.

Enums§

ActivityState
The lifecycle of an activity. More states may come, so a match needs a _ arm.
Alignment
AndroidPlacement
How Android keys the notification of an activity.
AndroidVisibility
Lock screen visibility of the Android notification.
Backend
Which backend shows an activity.
Bindable
A member that is a literal or Bound to a value. Only color, background, tint, opacity, size, weight and corner_radius of a Style, the background, keyline and url of a layout, the url of a link and the label, value and hint of a node’s accessibility can be bound.
ButtonStyle
Color
A semantic name, one hex color for both appearances, or a light and dark pair.
ColorName
ContentMode
ContentTransition
How the content of a node changes from one update to the next.
Dimension
A length in points, or "infinity" on the wire.
Element
What a node shows. The wire member type selects the variant.
EndPolicy
When an ended activity leaves the screen. More may come: match with a _ arm.
Event
What a platform reports of the application’s activities. More kinds may come: match with a _ arm.
ExpandedRegion
A region of the expanded Dynamic Island.
Fallback
What a start does when the platform cannot give the activity its native presentation.
FeatureSupport
Whether a backend provides a feature.
Font
A system text style.
FontDesign
FontWeight
HorizontalAlignment
IconSource
Android’s notification styles, for the AndroidContent of a snapshot. A TimerStyle takes liveupdate’s Timer, which is liveactivity::liveupdate::Timer. An icon the Android adapter may resolve without external storage access.
ImageSource
Where an image comes from.
IndicatorKind
Shape of a progress view or a gauge.
LayoutPush
What a layout activity asks ActivityKit for on iOS: a push token of its own ("token"), reported as a live-activity://push-token event once ActivityKit has it, or a broadcast channel the server made at APNs ({"channel": "<id>"}, iOS 18). Android ignores it. What a start asks for: a push token of the activity’s own, or a broadcast channel.
MetricValue
Android’s notification styles, for the AndroidContent of a snapshot. A TimerStyle takes liveupdate’s Timer, which is liveactivity::liveupdate::Timer. A value Android can render in MetricStyle on API 37 and later.
Padding
One number for every edge, or [top, leading, bottom, trailing].
PermissionKind
A permission that a request can ask for.
PermissionState
The state of one permission.
PresentationStyle
Android’s notification styles, for the AndroidContent of a snapshot. A TimerStyle takes liveupdate’s Timer, which is liveactivity::liveupdate::Timer. One Android system presentation style.
Privacy
Whether a node shows something private, the wire member privacy.
PromotionState
What Android did with a request to promote a notification to a Live Update.
PushCommand
What a push asks of an activity.
SemanticStyle
Android’s notification styles, for the AndroidContent of a snapshot. A TimerStyle takes liveupdate’s Timer, which is liveactivity::liveupdate::Timer. Android semantic color intent used by API 37 system styles.
SymbolRendering
TargetKind
Android’s notification styles, for the AndroidContent of a snapshot. A TimerStyle takes liveupdate’s Timer, which is liveactivity::liveupdate::Timer. What kind of component of the application an action’s target is.
Template
The two templates. More may come: match with a _ arm.
Transition
How a node with when or unless comes and goes, the wire member transition: the transitions the system runs in a Live Activity. Without one the node fades.
Value
One displayed value: text, a number or a flag. Strings are used as given, without normalization.
VerticalAlignment
Visibility
What is known of an activity being on screen.

Constants§

ERROR_CODES
Every code of the contract, on every platform and backend.
MAX_IMAGE_BYTES
The largest PNG write_image takes, in bytes.
MAX_IMAGE_HEIGHT
The largest height in pixels: the Lock Screen presentation’s 160 points at @3x.
MAX_IMAGE_WIDTH
The largest width in pixels: Apple’s largest Lock Screen presentation, 408 points wide, at @3x. Apple requires a Live Activity image to be no larger than its presentation.
TOKENS_KEPT
How many activities’ tokens a backend keeps, the newest.

Traits§

EventSink
Where a backend’s events go: implemented by a framework plugin, or any closure.
LiveActivityBackendapp
What a platform implements to show Live Activities: one method per command of the contract.
Validate
A request that can be checked against the contract.

Functions§

block_onapp
Drives future to its end on this thread.
check_image
Checks a name and a PNG as write_image does: the name follows the rule of a file source (^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$) and is INVALID_INPUT otherwise; the bytes are a PNG file, from its signature and image header to its end chunk, or INVALID_INPUT; a PNG of more than MAX_IMAGE_BYTES bytes, or wider or higher than MAX_IMAGE_WIDTH by MAX_IMAGE_HEIGHT pixels, is PAYLOAD_TOO_LARGE.
connect_nativeapp
The shortest connection: the default backend of the target platform, with sink for taps. The same as LiveActivity::builder().event_sink(sink).build().
parse_request
A JSON request of command as its typed input, checked against the contract: start, update and end of the templates, and start_layout, update_layout and end_layout, which are also read strictly, as activitykit does. A framework that receives requests as JSON parses them with this.
validate_request
Validate a JSON request without invoking any native API: start, update and end of contract v1, and start_layout, update_layout and end_layout of contract v2, which activitykit checks.
waitapp
The answer of a call, for code that cannot await: block_on with a guard. On the main thread of an iOS app the answer would never come, because activitykit answers there, so the call answers NATIVE_ERROR at once instead of hanging.
weight
Payload weight of a JSON value as the request contract defines it: an estimate that does not depend on the encoder, so that every layer agrees to the byte. The contract has no null; it weighs its four bytes here.
write_png
Checks the name and the PNG as check_image does, so that the name stays inside folder, then writes the PNG under name in folder, replacing an earlier one. The bytes go to a hidden file first and are then renamed, so the widget reads the old image or the new one, never part of it.

Type Aliases§

BackendFutureapp
Boxed future of the object-safe backend interface.
Layout
The member layout of a start: one tree per region, the two tints and the URL a tap opens. The layout is fixed when the activity starts; only a bound background, keyline or url follows the values.
Result
The result of every call of the contract.