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§
- android
app - The default Android backend: the
liveupdateengine, 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.
- ios
app - The iOS backend: the commands of the contract on activitykit.
- push
- Pushes from the application’s server: one
Messagefor an activity, theTargets that an application reports to its server, and theRequestof each platform, checked as the device checks the call it stands for. - testkit
testkit - 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,valueandhintare text of 1 to 200 code points orBoundto a value of any type, which is read as atextnode 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. - Action
Event - A tap on a button or a toggle node, or on an action of an Android content.
- Action
Target - Android’s notification styles, for the
AndroidContentof a snapshot. ATimerStyletakes liveupdate’sTimer, which isliveactivity::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. - Activity
Record - 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 (
alertin the capabilities); elsewhere the update is silent and the record reportsalertindegradedFeatures. More may come: build it withAlert::new. - Android
Content - 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.
- Android
Options - Options of a start that only Android reads. iOS ignores them. More may come: build it with
AndroidOptions::new. - Android
Presentation - Android’s notification styles, for the
AndroidContentof a snapshot. ATimerStyletakes liveupdate’sTimer, which isliveactivity::liveupdate::Timer. Resolved Android presentation attached to a schema-v2 snapshot. - Backend
Context - The event sink as a backend holds it, handed over in
attach. - BigText
Style - Android’s notification styles, for the
AndroidContentof a snapshot. ATimerStyletakes liveupdate’sTimer, which isliveactivity::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. - Builder
app - 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_CODESand a message. - Frame
- Sizes in points. At least one member.
- Handled
Event - 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 noEvent::Action: the component acted on it. - Image
Input - The input of the
write_imagecommand. - 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.
- Island
Expanded - The four regions of the expanded Dynamic Island.
- Island
Margins - 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. - Layout
Activity Record - A layout activity as the native side reports it. It does not repeat the layout.
- Layout
EndInput - 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. - Layout
Snapshot - The values a layout shows. An update replaces the whole map.
- Layout
Start Input - The input of
start_layout: a layout tree, its styles and its first values. - Layout
Update Input - The input of
update_layout: every value again, under a higher revision. - Live
Activity app - Live Activities of one application, on whichever backend it was connected to.
- Metric
- Android’s notification styles, for the
AndroidContentof a snapshot. ATimerStyletakes liveupdate’sTimer, which isliveactivity::liveupdate::Timer. One labeled metric. - Metric
Style - Android’s notification styles, for the
AndroidContentof a snapshot. ATimerStyletakes liveupdate’sTimer, which isliveactivity::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.
- Notification
Action - Android’s notification styles, for the
AndroidContentof a snapshot. ATimerStyletakes liveupdate’sTimer, which isliveactivity::liveupdate::Timer. One action button delivered back as ancrate::ActivityEvent. - Opened
Event - 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.
- Presentation
Capabilities - Android’s notification styles, for the
AndroidContentof a snapshot. ATimerStyletakes liveupdate’sTimer, which isliveactivity::liveupdate::Timer. Fine-grained Android system-presentation support. A member that a reply leaves out is false. - Progress
Point - Android’s notification styles, for the
AndroidContentof a snapshot. ATimerStyletakes liveupdate’sTimer, which isliveactivity::liveupdate::Timer. A colored marker on a rich progress track. - Progress
Segment - Android’s notification styles, for the
AndroidContentof a snapshot. ATimerStyletakes liveupdate’sTimer, which isliveactivity::liveupdate::Timer. A colored part of a rich progress track. - Progress
Style - Android’s notification styles, for the
AndroidContentof a snapshot. ATimerStyletakes liveupdate’sTimer, which isliveactivity::liveupdate::Timer. Android’s rich progress system style. - Public
Version - Android’s notification styles, for the
AndroidContentof a snapshot. ATimerStyletakes liveupdate’sTimer, which isliveactivity::liveupdate::Timer. What a secure lock screen shows instead of a private activity’s content. - Push
ToStart Token Event - The app’s push-to-start token, new or changed.
- Push
Token Event - A push token of an activity, new or changed.
- Push
Tokens - The push tokens a backend holds since launch.
- Pushed
Event - 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.
- Region
Priorities - 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.
- Samsung
NowBar - Android’s notification styles, for the
AndroidContentof a snapshot. ATimerStyletakes liveupdate’sTimer, which isliveactivity::liveupdate::Timer. Explicit Samsung Now Bar text mapping.SamsungNowBar::default()takes the title and the status. - Scheduled
Start - 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 receivesStatewithactivewhen it begins. iOS 26 and later, and Android where liveupdate’s library begins it (android_presentation.scheduled_start); elsewhere the start isUNSUPPORTED_FEATURE. - Snapshot
- The content of a template activity: a title, a status and either a progress or a timer.
- Start
Input - The input of
start: a progress or timer activity. - Started
Event - A layout activity that began while the application ran: one it started, or one a push started.
- State
Event - A new lifecycle state of an activity, of a template or a layout.
- Style
- Modifiers a node takes through its
styletoken. At least one member;fontandsizeexclude each other, and so dofont_familyanddesign. TheBindablemembers 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.
- Timer
Style - Android’s notification styles, for the
AndroidContentof a snapshot. ATimerStyletakes liveupdate’sTimer, which isliveactivity::liveupdate::Timer. Chronometer details for a timer presentation. - Unknown
Event - 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.
- Unsupported
Backend app - 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. - Update
Input - The input of
update: the whole content again, under a higher revision. - Updated
Event - Content that a push delivered to a layout activity.
Enums§
- Activity
State - The lifecycle of an activity. More states may come, so a match needs a
_arm. - Alignment
- Android
Placement - How Android keys the notification of an activity.
- Android
Visibility - Lock screen visibility of the Android notification.
- Backend
- Which backend shows an activity.
- Bindable
- A member that is a literal or
Boundto a value. Onlycolor,background,tint,opacity,size,weightandcorner_radiusof aStyle, thebackground,keylineandurlof a layout, theurlof a link and thelabel,valueandhintof a node’s accessibility can be bound. - Button
Style - Color
- A semantic name, one hex color for both appearances, or a light and dark pair.
- Color
Name - Content
Mode - Content
Transition - 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
typeselects 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. - Expanded
Region - A region of the expanded Dynamic Island.
- Fallback
- What a start does when the platform cannot give the activity its native presentation.
- Feature
Support - Whether a backend provides a feature.
- Font
- A system text style.
- Font
Design - Font
Weight - Horizontal
Alignment - Icon
Source - Android’s notification styles, for the
AndroidContentof a snapshot. ATimerStyletakes liveupdate’sTimer, which isliveactivity::liveupdate::Timer. An icon the Android adapter may resolve without external storage access. - Image
Source - Where an image comes from.
- Indicator
Kind - Shape of a progress view or a gauge.
- Layout
Push - What a layout activity asks ActivityKit for on iOS: a push token of its own (
"token"), reported as alive-activity://push-tokenevent 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. - Metric
Value - Android’s notification styles, for the
AndroidContentof a snapshot. ATimerStyletakes liveupdate’sTimer, which isliveactivity::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]. - Permission
Kind - A permission that a request can ask for.
- Permission
State - The state of one permission.
- Presentation
Style - Android’s notification styles, for the
AndroidContentof a snapshot. ATimerStyletakes liveupdate’sTimer, which isliveactivity::liveupdate::Timer. One Android system presentation style. - Privacy
- Whether a node shows something private, the wire member
privacy. - Promotion
State - What Android did with a request to promote a notification to a Live Update.
- Push
Command - What a push asks of an activity.
- Semantic
Style - Android’s notification styles, for the
AndroidContentof a snapshot. ATimerStyletakes liveupdate’sTimer, which isliveactivity::liveupdate::Timer. Android semantic color intent used by API 37 system styles. - Symbol
Rendering - Target
Kind - Android’s notification styles, for the
AndroidContentof a snapshot. ATimerStyletakes liveupdate’sTimer, which isliveactivity::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
whenorunlesscomes and goes, the wire membertransition: 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.
- Vertical
Alignment - 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_imagetakes, 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§
- Event
Sink - Where a backend’s events go: implemented by a framework plugin, or any closure.
- Live
Activity Backend app - 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_
on app - Drives
futureto its end on this thread. - check_
image - Checks a name and a PNG as
write_imagedoes: the name follows the rule of afilesource (^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$) and isINVALID_INPUTotherwise; the bytes are a PNG file, from its signature and image header to its end chunk, orINVALID_INPUT; a PNG of more thanMAX_IMAGE_BYTESbytes, or wider or higher thanMAX_IMAGE_WIDTHbyMAX_IMAGE_HEIGHTpixels, isPAYLOAD_TOO_LARGE. - connect_
native app - The shortest connection: the default backend of the target platform, with
sinkfor taps. The same asLiveActivity::builder().event_sink(sink).build(). - parse_
request - A JSON request of
commandas its typed input, checked against the contract:start,updateandendof the templates, andstart_layout,update_layoutandend_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,updateandendof contract v1, andstart_layout,update_layoutandend_layoutof contract v2, which activitykit checks. - wait
app - The answer of a call, for code that cannot await:
block_onwith a guard. On the main thread of an iOS app the answer would never come, because activitykit answers there, so the call answersNATIVE_ERRORat 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_imagedoes, so that the name stays insidefolder, then writes the PNG undernameinfolder, 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§
- Backend
Future app - Boxed future of the object-safe backend interface.
- Layout
- The member
layoutof 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 boundbackground,keylineorurlfollows the values. - Result
- The result of every call of the contract.