Assuming you're using something like this to end your live activities when the app is being terminated:
class func stopLiveActivities()
{
print("Ending Live Activities")
Task
{
for activity in Activity<TimeoutActivityAttributes>.activities
{
print("Ending Live Activity: \(activity.id)")
await activity.end(nil, dismissalPolicy: .immediate)
}
}
}
This will not end the activities, the method returns and allows the app to terminate before the activities get a chance to actually end.
Add a semaphore to force it to wait for the activities to end before returning from the method:
class func stopSessionTimeoutAsync()
{
print("Ending Live Activities")
let semaphore = DispatchSemaphore(value: 0)
Task
{
for activity in Activity<TimeoutActivityAttributes>.activities
{
print("Ending Live Activity: \(activity.id)")
await activity.end(nil, dismissalPolicy: .immediate)
}
semaphore.signal()
}
semaphore.wait()
}
This works for me (tested with a single activity). With the app in the background and live activity showing, I can force-kill the app and the live activity is removed.