ActivityAttributes
The protocol you implement to describe the content of a Live Activity.
Declaration
protocol ActivityAttributes : Decodable, EncodableMentioned in
Overview
The ActivityAttributes protocol describes the content that appears in your Live Activity. Its inner type ContentState represents the dynamic content of the Live Activity.
The following example shows an implementation of the ActivityAttributes protocol for a pizza delivery app. The app’s Live Activity shows the number of ordered pizzas and the total amount on the bill as static data and the name of the driver and an estimated delivery time as dynamic data that changes over time. Note how the implementation defines the type alias PizzaDeliveryStatus to make the code more descriptive and easier to read.
public import Foundation
import ActivityKit
struct PizzaDeliveryAttributes: ActivityAttributes {
public typealias PizzaDeliveryStatus = ContentState
public struct ContentState: Codable, Hashable {
var driverName: String
var deliveryTimer: ClosedRange<Date>
}
var numberOfPizzas: Int
var totalAmount: String
var orderNumber: String
}Topics
Dynamic content
Instance Methods
See Also
Starting a Live Activity
request(attributes:content:pushType:)request(attributes:content:pushType:style:)request(attributes:content:pushType:style:alertConfiguration:start:)request(attributes:content:pushType:style:alertConfiguration:startDate:)attributesActivityStylecontentActivityContentActivity.ContentStatePushTypeActivityAuthorizationError