### Starting a Live Activity with PushType Source: https://developer.apple.com/documentation/activitykit/pushtype Examples of how to start a Live Activity using different configurations of the `request` function with the `pushType` parameter. ```APIDOC ## Starting a Live Activity ### `request(attributes:content:pushType:)` Requests and starts a standard Live Activity. ### `request(attributes:content:pushType:style:)` Requests and starts a Live Activity with a specified style. ### `request(attributes:content:pushType:style:alertConfiguration:start:)` Requests and schedules a Live Activity for a specific date. ### `request(attributes:content:pushType:style:alertConfiguration:startDate:)` (Deprecated) Deprecated method for requesting and scheduling a Live Activity. ``` -------------------------------- ### Starting a Live Activity Source: https://developer.apple.com/documentation/activitykit/activitystyle Functions for requesting and starting Live Activities with various configurations. ```APIDOC ## Starting a Live Activity ### Requesting and Starting a Standard Live Activity ```swift static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?) throws -> Activity ``` ### Requesting and Starting a Live Activity with Style ```swift static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?, style: ActivityStyle) throws -> Activity ``` ### Requesting and Scheduling a Live Activity for a Specific Date ```swift static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?, style: ActivityStyle, alertConfiguration: AlertConfiguration, start: Date) throws -> Activity ``` ### Deprecated: Requesting and Scheduling a Live Activity for a Specific Date ```swift static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?, style: ActivityStyle, alertConfiguration: AlertConfiguration, startDate: Date) throws -> Activity ``` ### Related Properties and Types - `let attributes: Attributes`: A set of attributes that describe a Live Activity and its content. - `protocol ActivityAttributes`: The protocol you implement to describe the content of a Live Activity. - `var content: ActivityContent.ContentState>`: The dynamic content of a Live Activity. - `struct ActivityContent`: A structure that describes the state and configuration of a Live Activity. - `typealias ContentState`: The type alias for the structure that describes the dynamic content of a Live Activity. - `struct PushType`: The structure that offers constants you use to configure a Live Activity to receive updates through ActivityKit push notifications. - `enum ActivityAuthorizationError`: An error that indicates why the request to start a Live Activity failed. ``` -------------------------------- ### Starting a Live Activity - Related Methods Source: https://developer.apple.com/documentation/activitykit/activity/request%28attributes%3Acontent%3Apushtype%3Astyle%3Aalertconfiguration%3Astartdate%3A%29 Provides alternative methods for starting Live Activities, with varying parameters for push notifications and styles. ```APIDOC ## Related Methods for Starting Live Activities ### `static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?) throws -> Activity` Requests and starts a standard Live Activity. ### `static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?, style: ActivityStyle) throws -> Activity` Requests and starts a Live Activity with a specified style. ### `static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?, style: ActivityStyle, alertConfiguration: AlertConfiguration, start: Date) throws -> Activity` Requests and schedules a Live Activity for a specific date. (Note: This signature appears to have a typo in the parameter name 'start' instead of 'startDate' based on common conventions and the deprecated method.) ``` -------------------------------- ### Starting a Live Activity Source: https://developer.apple.com/documentation/activitykit/activity Methods for requesting and starting a Live Activity with various configurations for content, push notifications, style, and alerts. ```APIDOC ## Starting a Live Activity ### Description Methods for requesting and starting a Live Activity with various configurations for content, push notifications, style, and alerts. ### Methods #### `static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?) throws -> Activity` Requests and starts a standard Live Activity. #### `static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?, style: ActivityStyle) throws -> Activity` Requests and starts a Live Activity with a specified style. #### `static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?, style: ActivityStyle, alertConfiguration: AlertConfiguration, start: Date) throws -> Activity` Requests and schedules a Live Activity for a specific date with alert configuration. #### `static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?, style: ActivityStyle, alertConfiguration: AlertConfiguration, startDate: Date) throws -> Activity` (Deprecated) Deprecated method for requesting and scheduling a Live Activity with alert configuration and a start date. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (Parameters are passed directly to the method) ### Related Types - `let attributes: Attributes`: A set of attributes that describe a Live Activity and its content. - `protocol ActivityAttributes`: The protocol you implement to describe the content of a Live Activity. - `enum ActivityStyle`: Represents the visual style of a Live Activity. - `var content: ActivityContent.ContentState>`: The dynamic content of a Live Activity. - `struct ActivityContent`: A structure that describes the state and configuration of a Live Activity. - `typealias ContentState`: The type alias for the structure that describes the dynamic content of a Live Activity. - `struct PushType`: Constants for configuring ActivityKit push notifications. - `enum ActivityAuthorizationError`: Errors indicating why a request to start a Live Activity failed. - `struct AlertConfiguration`: Configures alerts for Live Activity updates. ``` -------------------------------- ### Starting a Live Activity Source: https://developer.apple.com/documentation/activitykit/activity/attributes Methods for requesting and starting a Live Activity using specific attributes and content states. ```APIDOC ## Static Methods: request ### Description Methods to request and start a standard or scheduled Live Activity. ### Methods - `static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?) throws -> Activity` - `static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?, style: ActivityStyle) throws -> Activity` - `static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?, style: ActivityStyle, alertConfiguration: AlertConfiguration, start: Date) throws -> Activity` ``` -------------------------------- ### Starting a Live Activity Source: https://developer.apple.com/documentation/activitykit/activityauthorizationerror Functions for requesting and starting Live Activities, including options for scheduling and push notifications. ```APIDOC ## Starting a Live Activity ### Requesting a Standard Live Activity ```swift static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?) throws -> Activity ``` ### Requesting a Live Activity with Style ```swift static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?, style: ActivityStyle) throws -> Activity ``` ### Requesting and Scheduling a Live Activity ```swift static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?, style: ActivityStyle, alertConfiguration: AlertConfiguration, start: Date) throws -> Activity ``` ### Deprecated: Requesting and Scheduling a Live Activity ```swift @available(*, deprecated, message: "Use the overload that accepts an `ActivityStyle`.") static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?, style: ActivityStyle, alertConfiguration: AlertConfiguration, startDate: Date) throws -> Activity ``` ### Related Properties and Types - **`attributes`** (Attributes): A set of attributes that describe a Live Activity and its content. - **`ActivityAttributes`** (protocol): The protocol you implement to describe the content of a Live Activity. - **`ActivityStyle`** (enum): Defines the style of a Live Activity. - **`content`** (ActivityContent.ContentState>): The dynamic content of a Live Activity. - **`ActivityContent`** (struct): A structure that describes the state and configuration of a Live Activity. - **`ContentState`** (typealias): The type alias for the structure that describes the dynamic content of a Live Activity. - **`PushType`** (struct): Constants for configuring a Live Activity to receive updates through ActivityKit push notifications. ``` -------------------------------- ### Start a Live Activity Source: https://developer.apple.com/documentation/activitykit/displaying-live-data-with-live-activities Initiates a Live Activity when the app is in the foreground. Requires ActivityAttributes and ActivityContent. Ensure activities are enabled before attempting to start. ```swift if ActivityAuthorizationInfo().areActivitiesEnabled { do { let adventure = AdventureAttributes(hero: hero) let initialState = AdventureAttributes.ContentState( currentHealthLevel: hero.healthLevel, eventDescription: "Adventure has begun!" ) let activity = try Activity.request( attributes: adventure, content: .init(state: initialState, staleDate: nil), pushType: .token ) self.setup(withActivity: activity) } catch { errorMessage = """ Couldn't start activity ------------------------ \(String(describing: error))" self.errorMessage = errorMessage } } ``` -------------------------------- ### Request and Start Live Activity Source: https://developer.apple.com/documentation/activitykit/activity/request%28attributes%3Acontent%3Apushtype%3A%29 Requests and starts a standard Live Activity. This method is used when your app is in the foreground. ```APIDOC ## POST /request ### Description Requests and starts a standard Live Activity. This method is used when your app is in the foreground. It can also be used to start a Live Activity that receives updates from the app using the `update(_:)` function. ### Method POST ### Endpoint /request ### Parameters #### Request Body - **attributes** (Attributes) - Required - A set of attributes that describe the Live Activity and its static content. - **content** (ActivityContent.ContentState>) - Required - A structure that describes the dynamic content of the Live Activity that changes over time. - **pushType** (PushType?) - Optional - A value that indicates whether the Live Activity receives updates to its dynamic content with ActivityKit push notifications. Pass `nil` to start a Live Activity that only receives updates from the app with the `update(_:)` function. To start a Live Activity that receives updates to its dynamic content with ActivityKit push notifications in addition to the `update(_:)` function, pass `token` to this parameter. ### Response #### Success Response (200) - **Activity** (Activity) - The object that represents the Live Activity you started. #### Error Response (400) - **ActivityAuthorizationError** - Thrown if the app can’t start a new Live Activity. For example, `ActivityAuthorizationError.denied` indicates that the person deactivated Live Activities for the app. ### Request Example ```swift static func request( attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType? = nil ) throws -> Activity ``` ### Response Example ```json { "activityId": "some-uuid", "attributes": { ... }, "contentState": { ... } } ``` ``` -------------------------------- ### Request and Start a Live Activity Source: https://developer.apple.com/documentation/activitykit/activity/request%28attributes%3Acontent%3Apushtype%3Astyle%3A%29 Use this method to request and start a Live Activity from your app while it’s in the foreground. Ensure image assets are not larger than the Live Activity presentation size. This method can throw `ActivityAuthorizationError` if the app cannot start a new Live Activity. ```swift static func request( attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType? = nil, style: ActivityStyle ) throws -> Activity ``` -------------------------------- ### Activity.request Source: https://developer.apple.com/documentation/activitykit/activityattributes Methods to request and start a Live Activity using defined attributes. ```APIDOC ## static func request ### Description Requests and starts a Live Activity. ### Parameters - **attributes** (Attributes) - Required - A set of attributes that describe a Live Activity and its content. - **content** (ActivityContent) - Required - The dynamic content of a Live Activity. - **pushType** (PushType) - Optional - Configures the activity to receive updates through push notifications. - **style** (ActivityStyle) - Optional - The style configuration for the Live Activity. - **alertConfiguration** (AlertConfiguration) - Optional - Configuration for alerts associated with the activity. - **start/startDate** (Date) - Optional - The date to start or schedule the Live Activity. ``` -------------------------------- ### POST /request Source: https://developer.apple.com/documentation/activitykit/activity/request%28attributes%3Acontent%3Apushtype%3Astyle%3A%29 Requests and starts a Live Activity from your app while it’s in the foreground. ```APIDOC ## POST /request ### Description Requests and starts a Live Activity. This method can only be called when your app is in the foreground. ### Method POST ### Endpoint `/request` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **attributes** (Attributes) - Required - A set of attributes that describe the Live Activity and its static content. - **content** (ActivityContent.ContentState>) - Required - A structure that describes the dynamic content of the Live Activity that changes over time. - **pushType** (PushType?) - Optional - A value that indicates whether the Live Activity receives updates to its dynamic content with ActivityKit push notifications. Pass `nil` to start a Live Activity that only receives updates from the app with the `update(_:)` function. To start a Live Activity that receives updates to its dynamic content with ActivityKit push notifications in addition to the `update(_:)` function, pass `token` to this parameter. - **style** (ActivityStyle) - Required - A flag that indicates whether the Live Activity uses standard or transient behavior. ### Request Example ```json { "attributes": { ... }, "content": { ... }, "pushType": "token" | null, "style": "standard" | "transient" } ``` ### Response #### Success Response (200) - **activity** (Activity) - The object that represents the Live Activity you started. #### Response Example ```json { "activity": { ... } } ``` ### Error Handling - **ActivityAuthorizationError** - Thrown if the app cannot start a new Live Activity. For example, `ActivityAuthorizationError.denied` indicates that the user deactivated Live Activities for the app. ``` -------------------------------- ### Observe Token Updates for Starting Live Activity via Push Source: https://developer.apple.com/documentation/activitykit/activity/pushtoken An asynchronous sequence to observe changes to the token used for starting a Live Activity with an ActivityKit push notification. ```swift `static var pushToStartTokenUpdates: Activity.PushTokenUpdates` ``` -------------------------------- ### Get Token to Start Live Activity via Push Source: https://developer.apple.com/documentation/activitykit/activity/pushtoken Retrieve the token used to initiate a Live Activity using an ActivityKit push notification. ```swift `static var pushToStartToken: Data?` ``` -------------------------------- ### Start Live Activity Payload (Pre-iOS 18) Source: https://developer.apple.com/documentation/activitykit/starting-and-updating-live-activities-with-activitykit-push-notifications This payload starts a Live Activity for devices not running iOS 18 and iPadOS 18 or later. Ensure the 'event' field is set to 'start' and include an 'alert' object. ```json { "aps": { "timestamp": 1234, "event": "start", "content-state": { "currentHealthLevel": 100, "eventDescription": "Adventure has begun!" }, "attributes-type": "AdventureAttributes", "attributes": { "hero": { "name": "Power Panda", "avatar": "U+1F43C", "healthLevel": 100, "heroType": "Forest Dweller", "healthRecoveryRatePerHour": 0.25, "url": "game:///panda", "battleCode": "game:///panda/battle", "level": 3, "exp": 600, "bio": "Power Panda loves eating bamboo shoots and leaves." } }, "alert": { "title": { "loc-key": "%@ is on an adventure!", "loc-args": [ "Power Panda" ] }, "body": { "loc-key": "%@ found a sword!", "loc-args": [ "Power Panda" ] }, "sound": "chime.aiff" } } } ``` -------------------------------- ### Request a Live Activity with Configuration Source: https://developer.apple.com/documentation/activitykit/activity/request%28attributes%3Acontent%3Apushtype%3Astyle%3Aalertconfiguration%3Astartdate%3A%29 Initiates a Live Activity with specific alert configuration and start date. This method is deprecated. ```swift static func request( attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType? = nil, style: ActivityStyle, alertConfiguration: AlertConfiguration, startDate: Date ) throws -> Activity ``` -------------------------------- ### Request and start a Live Activity Source: https://developer.apple.com/documentation/activitykit/activity/request%28attributes%3Acontentstate%3Apushtype%3A%29 Use this static method to initiate a Live Activity from the foreground. Note that this method is deprecated and requires specific attributes and content state. ```swift static func request( attributes: Attributes, contentState: Activity.ContentState, pushType: PushType? = nil ) throws -> Activity ``` -------------------------------- ### Observing Push Token Updates for Starting Live Activities Source: https://developer.apple.com/documentation/activitykit/activity/pushtostarttokenupdates This snippet demonstrates how to access the `pushToStartTokenUpdates` asynchronous sequence to monitor changes in the push token required for initiating a Live Activity using ActivityKit push notifications. This is crucial for ensuring your app has the latest token for starting new activities. ```APIDOC ## GET /websites/developer_apple_activitykit/pushToStartTokenUpdates ### Description An asynchronous sequence you use to observe changes to the token for starting a Live Activity with an ActivityKit push notification. ### Method GET ### Endpoint /websites/developer_apple_activitykit/pushToStartTokenUpdates ### Parameters This endpoint does not have explicit path or query parameters. The observation is managed through the ActivityKit framework. ### Request Body This endpoint does not accept a request body. ### Response #### Success Response (200) - **PushTokenUpdates** (Activity.PushTokenUpdates) - An asynchronous sequence that yields updated push tokens. #### Response Example ```swift // Example of observing token updates (conceptual) Task { for await token in Activity.pushToStartTokenUpdates { // Use the updated token to start a Live Activity print("New push token for starting activities: \(token)") } } ``` ### See Also - `var pushToken: Data?` - `var pushTokenUpdates: Activity.PushTokenUpdates` - `struct PushTokenUpdates` - `static var pushToStartToken: Data?` ``` -------------------------------- ### Start a Live Activity with a push token Source: https://developer.apple.com/documentation/activitykit/starting-and-updating-live-activities-with-activitykit-push-notifications Initiates a Live Activity by requesting a push token using the .token pushType parameter. ```swift func startActivity(hero: EmojiRanger) throws { let adventure = AdventureAttributes(hero: hero) let initialState = AdventureAttributes.ContentState( currentHealthLevel: hero.healthLevel, eventDescription: "Adventure has begun!" ) let activity = try Activity.request( attributes: adventure, content: .init(state: initialState, staleDate: nil), pushType: .token ) // ... } ``` -------------------------------- ### static func request(attributes:contentState:pushType:) Source: https://developer.apple.com/documentation/activitykit/activity/request%28attributes%3Acontentstate%3Apushtype%3A%29 Requests and starts a Live Activity. Note that this method is deprecated. ```APIDOC ## static func request(attributes:contentState:pushType:) ### Description Requests and starts a Live Activity. This method is deprecated. ### Method static func ### Parameters - **attributes** (Attributes) - Required - A set of attributes that describe the Live Activity and its static content. - **contentState** (Activity.ContentState) - Required - A structure that describes the dynamic content of the Live Activity that changes over time. - **pushType** (PushType?) - Optional - A value that indicates whether the Live Activity receives updates to its dynamic content with ActivityKit push notifications. ### Return Value - **Activity** - The object that represents the started Live Activity. ### Throws - **ActivityAuthorizationError** - Thrown if the app cannot start a new Live Activity, such as when Live Activities are deactivated for the app. ``` -------------------------------- ### ActivityAuthorizationError.missingProcessIdentifier Source: https://developer.apple.com/documentation/activitykit/activityauthorizationerror/missingprocessidentifier The process that tried to start the Live Activity is missing a process identifier. ```APIDOC ## ActivityAuthorizationError.missingProcessIdentifier ### Description The process that tried to start the Live Activity is missing a process identifier. ### Platform Availability iOS 16.1+ iPadOS 16.1+ ### Code Example ```swift case missingProcessIdentifier ``` ``` -------------------------------- ### Start a Live Activity with a channel ID Source: https://developer.apple.com/documentation/activitykit/starting-and-updating-live-activities-with-activitykit-push-notifications Initiates a Live Activity configured to receive updates via a specific channel ID. ```swift func startLiveActivityWithChannel(string channelId, initialState) { let activity = try Activity.request( attributes: adventure, content: .init(state: initialState, staleDate: nil), //Input your unique channel ID pushType: .channel(channelId) } ``` -------------------------------- ### Request Live Activity with Style Source: https://developer.apple.com/documentation/activitykit/activity/content Use this static function to request and start a Live Activity, specifying a particular style. Ensure you have the necessary attributes and content state defined. ```swift static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?, style: ActivityStyle) throws -> Activity ``` -------------------------------- ### Request a Live Activity Source: https://developer.apple.com/documentation/activitykit/activityattributes Use the `request` static method to start a Live Activity. This method requires attributes, content, and optionally a push type and activity style. ```swift static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?) throws -> Activity ``` ```swift static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?, style: ActivityStyle) throws -> Activity ``` ```swift static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?, style: ActivityStyle, alertConfiguration: AlertConfiguration, start: Date) throws -> Activity ``` ```swift static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?, style: ActivityStyle, alertConfiguration: AlertConfiguration, startDate: Date) throws -> Activity ``` -------------------------------- ### Initialize ActivityAuthorizationInfo Source: https://developer.apple.com/documentation/activitykit/activityauthorizationinfo/activityenablementupdates-swift.struct Creates an object used to observe user authorizations for starting and updating Live Activities via ActivityKit push notifications. ```swift init() ``` -------------------------------- ### Request Standard Live Activity Source: https://developer.apple.com/documentation/activitykit/activity/content Use this static function to request and start a standard Live Activity. Ensure you have the necessary attributes and content state defined. ```swift static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?) throws -> Activity ``` -------------------------------- ### Observing Live Activity Permission Changes Source: https://developer.apple.com/documentation/activitykit/activityauthorizationinfo APIs to observe whether your app is authorized to start Live Activities. ```APIDOC ## Observing Live Activity permission changes ### `areActivitiesEnabled` Property - **Description**: A Boolean value that indicates whether your app can start a Live Activity. - **Type**: `Bool` ### `activityEnablementUpdates` Property - **Description**: An asynchronous sequence you use to observe whether your app can start a Live Activity. - **Type**: `ActivityAuthorizationInfo.ActivityEnablementUpdates` ### `ActivityEnablementUpdates` Struct - **Description**: A structure that offers functionality to observe whether your app can start a Live Activity. ### `init()` Initializer - **Description**: Creates an object you use to observe user authorizations for starting Live Activities and updating them with ActivityKit push notifications. - **Type**: `init()` ``` -------------------------------- ### Start Live Activity Payload with Push Token (iOS 18+) Source: https://developer.apple.com/documentation/activitykit/starting-and-updating-live-activities-with-activitykit-push-notifications This payload starts a Live Activity on devices running iOS 18 and iPadOS 18 or later and allows you to receive a new push token for sending updates. The 'input-push-token' field should be set to '1'. ```json "input-push-token": 1, "attributes-type": "AdventureAttributes", "attributes": { "currentHealthLevel": 100, "eventDescription": "Adventure has begun!" } ``` -------------------------------- ### Start Live Activity Payload with Push Channel (iOS 18+) Source: https://developer.apple.com/documentation/activitykit/starting-and-updating-live-activities-with-activitykit-push-notifications For devices running iOS 18 and iPadOS or later, this payload starts a Live Activity and enables listening for updates on a specified push channel. The 'input-push-channel' field requires a valid channel ID. ```json "input-push-channel": "dHN0LXNyY2gtY2hubA==", "attributes-type": "AdventureAttributes", "attributes": { "currentHealthLevel": 100, "eventDescription": "Adventure has begun!" } ``` -------------------------------- ### Accessing pushToStartTokenUpdates Source: https://developer.apple.com/documentation/activitykit/activity/pushtostarttokenupdates Use this static property to monitor changes to the push token required for starting Live Activities. ```swift static var pushToStartTokenUpdates: Activity.PushTokenUpdates { get } ``` -------------------------------- ### ActivityState.pending Source: https://developer.apple.com/documentation/activitykit/activitystate/pending Represents the state where a Live Activity is scheduled to start at a future date but has not yet commenced. ```APIDOC ## ActivityState.pending ### Description The Live Activity is scheduled to start at a specified date but hasn’t started yet. ### Availability - iOS 26.0+ - iPadOS 26.0+ ### Definition ```swift case pending ``` ``` -------------------------------- ### Request and Schedule Live Activity Source: https://developer.apple.com/documentation/activitykit/activity/request%28attributes%3Acontent%3Apushtype%3Astyle%3Aalertconfiguration%3Astart%3A%29 Use this method to request and schedule a Live Activity for a specific date. Ensure you provide an `AlertConfiguration` to notify users when the activity starts. This method can be used while the app is in the foreground. ```swift static func request( attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType? = nil, style: ActivityStyle, alertConfiguration: AlertConfiguration, start: Date ) throws -> Activity ``` -------------------------------- ### ActivityAuthorizationError Cases Source: https://developer.apple.com/documentation/activitykit/activityauthorizationerror/visibility A list of error cases that can occur when attempting to start or manage Live Activities in ActivityKit. ```APIDOC ## ActivityAuthorizationError Cases ### Description Enumeration of errors that occur when an app attempts to start or manage a Live Activity. ### Error Cases - **visibility**: The app tried to start the Live Activity while it was in the background. - **attributesTooLarge**: The provided Live Activity attributes exceeded the maximum size of 4KB. - **denied**: A person deactivated Live Activities in Settings. - **globalMaximumExceeded**: The device reached the maximum number of ongoing Live Activities. - **malformedActivityIdentifier**: The provided activity identifier is malformed. - **missingProcessIdentifier**: The process that tried to start the Live Activity is missing a process identifier. - **persistenceFailure**: The system couldn’t persist the Live Activity. - **reconnectNotPermitted**: The process that tried to recreate the Live Activity is not the process that originally created the Live Activity. - **targetMaximumExceeded**: The app has already started the maximum number of concurrent Live Activities. - **unentitled**: The app doesn’t have the required entitlement to start a Live Activity. - **unsupported**: The device doesn’t support Live Activities. - **unsupportedTarget**: The app doesn’t have the required entitlement to start a Live Activities. ``` -------------------------------- ### Request Live Activity Source: https://developer.apple.com/documentation/activitykit/activity/request%28attributes%3Acontent%3Apushtype%3A%29 Use this method to request and start a standard Live Activity from your app while it's in the foreground. Ensure JavaScript is enabled in your browser for full functionality. ```swift static func request( attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType? = nil ) throws -> Activity ``` -------------------------------- ### Observe Live Activity Changes Source: https://developer.apple.com/documentation/activitykit/activity/activityupdates-swift.struct An asynchronous sequence used to observe changes to ongoing Live Activities. It also allows asynchronous access to a Live Activity when it is started. ```swift static var activityUpdates: Activity.ActivityUpdates ``` -------------------------------- ### Request and Schedule Live Activity Source: https://developer.apple.com/documentation/activitykit/activity/request%28attributes%3Acontent%3Apushtype%3Astyle%3Aalertconfiguration%3Astart%3A%29 Requests and schedules a Live Activity for a specific date. This method can be used to start a Live Activity from your app while it's in the foreground. ```APIDOC ## POST /request ### Description Requests and schedules a Live Activity for a specific date. This method can be used to start a Live Activity from your app while it's in the foreground. ### Method POST ### Endpoint /request ### Parameters #### Request Body - **attributes** (Attributes) - Required - A set of attributes that describe the Live Activity and its static content. - **content** (ActivityContent.ContentState>) - Required - A structure that describes the dynamic content of the Live Activity that changes over time. - **pushType** (PushType?) - Optional - A value that indicates whether the Live Activity receives updates to its dynamic content with ActivityKit push notifications. Pass `nil` to start a Live Activity that only receives updates from the app with the `update(_:)` function. To start a Live Activity that receives updates to its dynamic content with ActivityKit push notifications in addition to the `update(_:)` function, pass `token` to this parameter. - **style** (ActivityStyle) - Required - A flag that indicates whether the Live Activity uses standard or transient behavior. - **alertConfiguration** (AlertConfiguration) - Required - The alert configuration you use to configure how the system notifies a person about the updated content of the Live Activity. - **start** (Date) - Required - The date to schedule the start of your Live Activity; for example, for an upcoming sports game. You must provide an `alertConfiguration` to let people know that your app started a Live Activity. The `ActivityState` for a scheduled but not yet started Live Activity is `ActivityState.pending`. ### Response #### Success Response (200) - **Activity** (Activity) - The object that represents the Live Activity you started. #### Error Response - **ActivityAuthorizationError** - Thrown if the app can’t start a new Live Activity. For example, `ActivityAuthorizationError.denied` indicates that the person deactivated Live Activities for the app. ``` -------------------------------- ### Initializer: init(state:staleDate:relevanceScore:) Source: https://developer.apple.com/documentation/activitykit/activitycontent/init%28state%3Astaledate%3Arelevancescore%3A%29 Creates the object that describes the state and configuration of a Live Activity. ```APIDOC ## Initializer: init(state:staleDate:relevanceScore:) ### Description Creates the object that describes the state and configuration of a Live Activity. ### Method Initializer ### Endpoint N/A (Initializer) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```swift init( state: State, staleDate: Date?, relevanceScore: Double = 0.0 ) ``` ### Response #### Success Response (200) N/A (Initializer) #### Response Example N/A (Initializer) ### See Also - `State`: The current state of a Live Activity in its life cycle. - `staleDate`: The date when the system considers the Live Activity to be out of date. - `relevanceScore`: A score you assign that determines the order in which your Live Activities appear when you start several Live Activities for your app. ``` -------------------------------- ### Access Current Live Activities Source: https://developer.apple.com/documentation/activitykit/activity/activityupdates-swift.struct Provides an array of your app's currently active Live Activities. Use this to get a snapshot of all ongoing activities. ```swift static var activities: [Activity] ``` -------------------------------- ### Get ActivityKit Error Domain Source: https://developer.apple.com/documentation/activitykit/activityauthorizationerror/errordomain Use this property to access the domain for errors related to starting Live Activities. Available on iOS 16.1+ and iPadOS 16.1+. ```swift static var errorDomain: String { get } ``` -------------------------------- ### init(title:body:sound:) Source: https://developer.apple.com/documentation/activitykit/alertconfiguration/init%28title%3Abody%3Asound%3A%29 Initializes a new alert configuration for a Live Activity update. ```APIDOC ## init(title:body:sound:) ### Description Initializes a new alert configuration for a Live Activity update. ### Parameters - **title** (LocalizedStringResource) - Required - The short title that describes the purpose of the Live Activity update. - **body** (LocalizedStringResource) - Required - The main text of the alert for a Live Activity update. - **sound** (AlertConfiguration.AlertSound) - Required - The sound that the system plays when the alert appears on a person’s device. ### Request Example ```swift init( title: "Update Title", body: "The main alert text.", sound: .default ) ``` ``` -------------------------------- ### Specify Broadcast Push Channel for Live Activity Source: https://developer.apple.com/documentation/activitykit/pushtype/channel%28_%3A%29 Example of how to request a Live Activity update using a specific broadcast push channel. Ensure the channel ID is correctly base64-encoded. ```swift Activity.request(attributes: attributes, content: content, pushType: .channel("c29tZUNoYW5uZWw=")) ``` -------------------------------- ### Request and Schedule Live Activity (Deprecated) Source: https://developer.apple.com/documentation/activitykit/activity/content Deprecated: Use this static function to request and schedule a Live Activity for a specific future date. Ensure you have the necessary attributes, content, push type, style, alert configuration, and start date. ```swift static func request(attributes: Attributes, content: ActivityContent.ContentState>, pushType: PushType?, style: ActivityStyle, alertConfiguration: AlertConfiguration, startDate: Date) throws -> Activity ``` -------------------------------- ### POST /request Source: https://developer.apple.com/documentation/activitykit/activity/request%28attributes%3Acontent%3Apushtype%3Astyle%3Aalertconfiguration%3Astart%3A%29 Methods to initiate a new Live Activity session with varying levels of configuration. ```APIDOC ## POST /request ### Description Requests and starts a new Live Activity session. ### Method POST ### Parameters #### Request Body - **attributes** (Attributes) - Required - A set of attributes that describe a Live Activity and its content. - **content** (ActivityContent.ContentState>) - Required - The dynamic content of a Live Activity. - **pushType** (PushType) - Optional - Constants used to configure a Live Activity to receive updates through push notifications. - **style** (ActivityStyle) - Optional - The style configuration for the Live Activity. - **alertConfiguration** (AlertConfiguration) - Optional - Configuration for alerts associated with the activity. - **startDate** (Date) - Optional - The start date for the activity. ### Response #### Success Response (200) - **Activity** (Activity) - Returns the initiated Activity instance. ### Error Handling - **ActivityAuthorizationError** - Indicates why the request to start a Live Activity failed. ``` -------------------------------- ### Observe Live Activity Enablement Changes Source: https://developer.apple.com/documentation/activitykit/activityauthorizationinfo/activityenablementupdates-swift.struct An asynchronous sequence used to observe changes in whether the app can start a Live Activity. This is the primary mechanism for monitoring Live Activity permissions. ```swift let activityEnablementUpdates: ActivityAuthorizationInfo.ActivityEnablementUpdates ``` -------------------------------- ### Initialize AlertConfiguration Source: https://developer.apple.com/documentation/activitykit/alertconfiguration/init%28title%3Abody%3Asound%3A%29 Use this initializer to define the title, body, and sound for a Live Activity alert. ```swift init( title: LocalizedStringResource, body: LocalizedStringResource, sound: AlertConfiguration.AlertSound ) ``` -------------------------------- ### Request Live Activity (Deprecated) Source: https://developer.apple.com/documentation/activitykit/activity/request%28attributes%3Acontent%3Apushtype%3Astyle%3Aalertconfiguration%3Astartdate%3A%29 This method requests and starts a Live Activity with specific alert configurations and a start date. It is deprecated in iOS 26.0 and iPadOS 26.0. ```APIDOC ## POST /request ### Description Requests and starts a Live Activity with alert configuration and a specified start date. This method is deprecated. ### Method POST ### Endpoint `/request` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **attributes** (Attributes) - Required - A set of attributes that describe a Live Activity and its content. - **content** (ActivityContent.ContentState>) - Required - The dynamic content of a Live Activity. - **pushType** (PushType?) - Optional - Configuration for receiving updates through ActivityKit push notifications. - **style** (ActivityStyle) - Required - The style of the Live Activity. - **alertConfiguration** (AlertConfiguration) - Required - Configuration for alerts associated with the Live Activity. - **startDate** (Date) - Required - The date when the Live Activity should start. ### Request Example ```json { "attributes": { ... }, "content": { ... }, "pushType": null, "style": "..., "alertConfiguration": { ... }, "startDate": "2023-10-27T10:00:00Z" } ``` ### Response #### Success Response (200) - **activity** (Activity) - The started Live Activity. #### Response Example ```json { "activity": { ... } } ``` ``` -------------------------------- ### Initialize ActivityContent Source: https://developer.apple.com/documentation/activitykit/activitycontent/relevancescore Constructor for defining the state, stale date, and relevance score of a Live Activity. ```swift init(state: State, staleDate: Date?, relevanceScore: Double) ``` -------------------------------- ### ActivityAuthorizationInfo init() Source: https://developer.apple.com/documentation/activitykit/activityauthorizationinfo/init%28%29 Initializes an object to observe user authorizations for Live Activities. ```APIDOC ## init() ### Description Creates an object you use to observe user authorizations for starting Live Activities and updating them with ActivityKit push notifications. ### Availability - iOS 16.1+ - iPadOS 16.1+ ### Syntax ```swift init() ``` ``` -------------------------------- ### Generate Live Activity Preview Source: https://developer.apple.com/documentation/activitykit/activityattributes/previewcontext%28_%3Aisstale%3Aviewkind%3A%29 Use this method to generate a preview for a Live Activity. Provide the content state, a boolean indicating staleness, and the desired view kind for the presentation. ```swift func previewContext( _ contentState: Self.ContentState, isStale: Bool = false, viewKind: ActivityPreviewViewKind ) -> some View ``` -------------------------------- ### Configure Live Activity with Supplemental Families Source: https://developer.apple.com/documentation/activitykit/creating-custom-views-for-live-activities Configure a Live Activity to provide different view layouts for small and medium activity families using `supplementalActivityFamilies`. This ensures your Live Activity adapts to various presentations. ```swift struct AdventureActivityConfiguration: Widget { var body: some WidgetConfiguration { ActivityConfiguration(for: AdventureAttributes.self) { context in // Create the presentation that appears on the Lock Screen and as a // banner on the Home Screen of devices that don't support the // Dynamic Island. // ... } dynamicIsland: { context in // Create the presentations that appear in the Dynamic Island. DynamicIsland { // Create the expanded presentation. // ... } compactLeading: { // Create the compact leading presentation. // ... } compactTrailing: { // Create the compact trailing presentation. // ... } minimal: { // Create the minimal presentation. // ... } } ..supplementalActivityFamilies([.small, .medium]) } } ``` -------------------------------- ### ActivityKit Error Domain Source: https://developer.apple.com/documentation/activitykit/activityauthorizationerror/errorcode The domain for errors that can occur when starting a Live Activity. ```APIDOC ## See Also ### Protocol Confirmation `static var errorDomain: String` The domain for errors that can happen when starting a Live Activity. ``` -------------------------------- ### Initializing a Live Activity Source: https://developer.apple.com/documentation/activitykit/activitycontent/relevancescore This initializer is used to create an object that describes the state and configuration of a Live Activity, including its relevance score. ```APIDOC ### See Also #### Describing a Live Activity `init(state: State, staleDate: Date?, relevanceScore: Double)` Creates the object that describes the state and configuration of a Live Activity. ``` -------------------------------- ### ActivityAuthorizationInfo.areActivitiesEnabled Source: https://developer.apple.com/documentation/activitykit/activityauthorizationinfo/areactivitiesenabled A property that indicates whether the application is currently authorized to start a Live Activity. ```APIDOC ## Property: areActivitiesEnabled ### Description A Boolean value that indicates whether your app can start a Live Activity. ### Availability - iOS 16.1+ - iPadOS 16.1+ ### Declaration `final var areActivitiesEnabled: Bool { get }` ``` -------------------------------- ### ActivityAuthorizationError.targetMaximumExceeded Source: https://developer.apple.com/documentation/activitykit/activityauthorizationerror/targetmaximumexceeded Indicates that the app has already started the maximum number of concurrent Live Activities. ```APIDOC ## ActivityAuthorizationError.targetMaximumExceeded ### Description The app has already started the maximum number of concurrent Live Activities. ### Supported Platforms iOS 16.1+ iPadOS 16.1+ ### Code Example ```swift case targetMaximumExceeded ``` ``` -------------------------------- ### Configure Live Activity Presentations Source: https://developer.apple.com/documentation/activitykit/displaying-live-data-with-live-activities Defines the compact leading and trailing views for a Live Activity using the ActivityConfiguration and DynamicIsland structures. ```swift import SwiftUI import WidgetKit struct AdventureActivityConfiguration: Widget { var body: some WidgetConfiguration { ActivityConfiguration(for: AdventureAttributes.self) { context in // Create the presentation that appears on the Lock Screen and as a // banner on the Home Screen of devices that don't support the // Dynamic Island. // ... } dynamicIsland: { context in // Create the presentations that appear in the Dynamic Island. DynamicIsland { // Create the expanded presentation. // ... } compactLeading: { // Create the compact leading presentation. Avatar(hero: context.attributes.hero, includeBackground: true) .accessibilityLabel("The avatar of \(context.attributes.hero.name).") } compactTrailing: { // Create the compact trailing presentation. ProgressView(value: context.state.currentHealthLevel, total: 1) { let healthLevel = Int(context.state.currentHealthLevel * 100) Text("\(healthLevel)") .accessibilityLabel("Health level at \(healthLevel) percent.") } .progressViewStyle(.circular) .tint(context.state.currentHealthLevel <= 0.2 ? Color.red : Color.green) } minimal: { // Create the minimal presentation. // ... } } } } ``` -------------------------------- ### GET makeAsyncIterator() Source: https://developer.apple.com/documentation/activitykit/activity/pushtokenupdates-swift.struct/makeasynciterator%28%29 Creates an asynchronous iterator that produces results from the Activity.PushTokenUpdates asynchronous sequence. ```APIDOC ## makeAsyncIterator() ### Description Creates the asynchronous iterator that produces results from this asynchronous sequence. ### Method Instance Method ### Signature `func makeAsyncIterator() -> Activity.PushTokenUpdates.Iterator` ### Availability - iOS 16.1+ - iPadOS 16.1+ ``` -------------------------------- ### GET makeAsyncIterator() Source: https://developer.apple.com/documentation/activitykit/activity/activityupdates-swift.struct/makeasynciterator%28%29 Creates an asynchronous iterator that produces results from the ActivityUpdates asynchronous sequence. ```APIDOC ## makeAsyncIterator() ### Description Creates the asynchronous iterator that produces results from this asynchronous sequence. ### Method Instance Method ### Signature `func makeAsyncIterator() -> Activity.ActivityUpdates.Iterator` ### Availability - iOS 16.1+ - iPadOS 16.1+ ``` -------------------------------- ### ActivityAuthorizationError.unsupported Source: https://developer.apple.com/documentation/activitykit/activityauthorizationerror/unsupported The device doesn’t support Live Activities. ```APIDOC ## ActivityAuthorizationError.unsupported ### Description The device doesn’t support Live Activities. ### Supported Platforms iOS 16.1+ iPadOS 16.1+ ### Code Example ```swift case unsupported ``` ``` -------------------------------- ### ActivityAuthorizationError Enumeration Source: https://developer.apple.com/documentation/activitykit/activityauthorizationerror The ActivityAuthorizationError enumeration defines the possible errors that can occur when attempting to start a Live Activity. ```APIDOC ## Enumeration: ActivityAuthorizationError An error that indicates why the request to start a Live Activity failed. ### Error Codes - **`attributesTooLarge`**: The provided Live Activity attributes exceeded the maximum size of 4KB. - **`denied`**: A person deactivated Live Activities in Settings. - **`globalMaximumExceeded`**: The device reached the maximum number of ongoing Live Activities. - **`malformedActivityIdentifier`**: The provided activity identifier is malformed. - **`missingProcessIdentifier`**: The process that tried to start the Live Activity is missing a process identifier. - **`persistenceFailure`**: The system couldn’t persist the Live Activity. - **`reconnectNotPermitted`**: The process that tried to recreate the Live Activity is not the process that originally created the Live Activity. - **`targetMaximumExceeded`**: The app has already started the maximum number of concurrent Live Activities. - **`unentitled`**: The app doesn’t have the required entitlement to start a Live Activity. - **`unsupported`**: The device doesn’t support Live Activities. - **`unsupportedTarget`**: The app doesn’t have the required entitlement to start a Live Activities. - **`visibility`**: The app tried to start the Live Activity while it was in the background. ### Getting Error Information - **`failureReason`** (String?): A string that describes the error that occurred. - **`recoverySuggestion`** (String?): A localized message that describes how to recover from the error. ### Protocol Confirmations This enumeration conforms to the following protocols: - `Copyable` - `CustomNSError` - `Equatable` - `Error` - `Escapable` - `Hashable` - `LocalizedError` - `Sendable` - `SendableMetatype` ``` -------------------------------- ### Get ActivityKit Error Code Source: https://developer.apple.com/documentation/activitykit/activityauthorizationerror/errordomain An integer value representing the specific error code. This is a confirmation of the Protocol. ```swift var errorCode: Int ``` -------------------------------- ### Initialize Live Activity State Source: https://developer.apple.com/documentation/activitykit/activitycontent/init%28state%3Astaledate%3Arelevancescore%3A%29 Use this initializer to create the object that describes the state and configuration of a Live Activity. It requires the current state, an optional stale date, and a relevance score. ```swift init( state: State, staleDate: Date?, relevanceScore: Double = 0.0 ) ``` -------------------------------- ### ActivityAuthorizationError.persistenceFailure Source: https://developer.apple.com/documentation/activitykit/activityauthorizationerror/persistencefailure The system couldn’t persist the Live Activity. This error is available starting from iOS 16.1 and iPadOS 16.1. ```APIDOC ## ActivityAuthorizationError.persistenceFailure ### Description The system couldn’t persist the Live Activity. ### Availability iOS 16.1+ iPadOS 16.1+ ### Code Example ```swift case persistenceFailure ``` ``` -------------------------------- ### next() Instance Method Source: https://developer.apple.com/documentation/activitykit/activityauthorizationinfo/activityenablementupdates-swift.struct/iterator/next%28%29 Asynchronously advances to the next element in the sequence of activity enablement updates. ```APIDOC ## next() ### Description Asynchronously advances to the next element and returns it, or ends the sequence if there is no next element. ### Method Instance Method ### Signature `mutating func next() async -> Bool?` ### Availability - iOS 16.1+ - iPadOS 16.1+ ```