iOS Live Activities
A Live Activity displays current data from your app on the iPhone Lock Screen and in the Dynamic Island. Live Activities are an AXP feature.
Live Activities overview
A Live Activity can be created when the app is in the foreground or through a notification action button. You can update a Live Activity within eight hours of creation and display it for up to four hours after the last update.
For example, to provide updates for tracking a sports game, create a Live Activity with name sports-game-123
. The app will track and display changes through the Airship SDK using that name. The name can be unique to a single device or shared across multiple devices.
Minimum SDK required: iOS 16.10.0.
Updates to Live Activities are made through push notifications and/or background tasks in the app. For more timely updates, Airship recommends using push notifications or push notifications in addition to background tasks.
When updating through push notifications, APNs allows a certain budget of updates per hour. If an app exceeds this budget, notifications will be throttled. To avoid being throttled, a mix of low priority (priority 5) and high priority notifications (priority 10) can be used.
In addition to priorities and background tasks, if a use case requires frequent push updates, an app can also set the plist flag NSSupportsLiveActivitiesFrequentUpdates to prevent being throttled. However, the end user is able to disable frequent updates in the app settings.
For more information on implementing Live Activities, see Apple documentation:
Multiple Live Activities can be started by an app, and a device can show multiple activities from different apps, the maximum number of which may depend on a range of factors.
Live Activities require token-based authentication for APNs. See: iOS Channel Configuration.
Airship support for Live Activities
Airship’s Live Activity support allows tracking each Live Activity’s unique push token by a name on the app’s channel. The name can then be used to send updates to a Live Activity. The name can be unique to the device or shared across multiple devices. Airship handles mapping the name back to the token for the specified audience and sends an update to each token.
Live Activity tokens are tracked in the App channel. They do not increase your billable audience.
Tracking activities
To support Live Activities, you must call restore once after takeOff during application(_:didFinishLaunchingWithOptions:)
with all the Live Activity types that you might track with Airship. This allows Airship to resume tracking of any previously tracked activities across app inits.
Airship.takeOff(config, launchOptions: launchOptions)
Airship.channel.restoreLiveActivityTracking { restorer in
await restorer.restore(
forType: Activity<DeliveryAttributes>.self
)
await restorer.restore(
forType: Activity<SomeOtherAttributes>.self
)
}
Once a Live Activity is created, you can then track it with Airship using:
let activity = try Activity.request(
attributes: attributes,
contentState: state,
pushType: .token
)
Airship.channel.trackLiveActivity(
activity,
name: "order-1234"
)
Sending updates
Once an activity is tracked with Airship, you can send an update through the Push API by specifying a live_activity
payload.
In this example, an update is being sent to all channels that have a Live Activity named order-1234
. An audience can be specified to restrict who receives the update.
{
"audience": "all",
"device_types": [
"ios"
],
"notification": {
"ios": {
"live_activity": {
"name": "order-1234",
"event": "update",
"content_state": {
"stopsAway": "0",
"driver": "Jeff Moleyes"
},
"dismissal_date": 1666261020,
"alert": {
"title": "Order Delivered",
"body": "Hope you enjoy!"
},
"priority": 10,
"stale_date": 1666261020,
"relevance_score": 50
}
}
}
}
Categories