# Live Activities for the Apple SDK

Integrate Live Activities into your iOS app to display real-time updates on the Lock Screen and Dynamic Island. {{< badge "axp" >}}


For the push API method, see the [iOS Live Activities](https://www.airship.com/docs/guides/messaging/features/ios-live-activities/) messaging guide. See also the [iOS Live Activities](https://www.airship.com/docs/guides/features/messaging/live-activities-updates/) feature guide.

## App Setup

To support Live Activities, you must call `restoreLiveActivityTracking` *once* after `takeOff` with all the Live Activity types that you might track with Airship. This allows Airship to resume tracking any previously tracked activities across app inits and to automatically track the `pushToStartToken` that allows starting activities through a push notification.


#### Swift


```swift
Airship.takeOff(config, launchOptions: launchOptions)

Airship.channel.restoreLiveActivityTracking { restorer in
    await restorer.restore(forType: Activity<SportsActivityAttributes>.self)
    await restorer.restore(forType: Activity<SomeOtherAttributes>.self)
}
```



#### Objective-C


> **Note:** Live Activities are not supported in Objective-C. Use Swift for Live Activity implementation.




After the `restore` call above, Airship will track the `pushToStartTokens` for the activity's attribute types. You can then start a Live Activity through a push notification. Starting a Live Activity does not automatically track it. Instead, the app will be woken up and you must call through to Airship with the activity instance and the name.

### Watching for Live Activities

There is no entry point into the app when it is started for a Live Activity being created. Instead, you need to query Live Activities on init and when a `pushToStartToken` update is received to track them through Airship. Airship provides an extension `Activity<T>.airshipWatchActivities(activityBlock:)` that can be used to do this for you.

In this example, we assume the `gameID` on our `SportsActivityAttributes` will be used to send updates through Airship after it is created:


#### Swift


```swift
Airship.channel.restoreLiveActivityTracking { restorer in
    await restorer.restore(forType: Activity<SportsActivityAttributes>.self)
}

Activity<SportsActivityAttributes>.airshipWatchActivities { activity in
    Airship.channel.trackLiveActivity(activity, name: activity.attributes.gameID)
}
```



#### Objective-C


> **Note:** Live Activities are not supported in Objective-C. Use Swift for Live Activity implementation.




## Starting Live Activities

To start a Live Activity from the app, make sure to set the `pushType` to `.token`. After it is started, immediately track it with `Airship.channel.trackLiveActivity(_:name:)`.


#### Swift


```swift
let activity = try Activity.request(
    attributes: attributes,
    content: content,
    pushType: .token
)

Airship.channel.trackLiveActivity(
    activity,
    name: attributes.gameID
)
```



#### Objective-C


> **Note:** Live Activities are not supported in Objective-C. Use Swift for Live Activity implementation.




## Updating Live Activities

To update a Live Activity, use the standard ActivityKit APIs. First find the Activity instance then call `update` on it:


#### Swift


```swift
guard
    let activity = Activity<SportsActivityAttributes>.activities.first(where: { $0.id == "sports-game-123" })
else {
    // not found
    return
}
activity.update(contentUpdate)
```



#### Objective-C


> **Note:** Live Activities are not supported in Objective-C. Use Swift for Live Activity implementation.




## Ending Live Activities

To end a Live Activity, use the standard ActivityKit APIs. First find the Activity instance then call `end` on it with a dismissal policy:


#### Swift


```swift
guard
    let activity = Activity<SportsActivityAttributes>.activities.first(where: { $0.id == "sports-game-123" })
else {
    // not found
    return
}

activity.end(contentUpdate, dismissalPolicy: .default)
```



#### Objective-C


> **Note:** Live Activities are not supported in Objective-C. Use Swift for Live Activity implementation.



