Dismiss Live Activities on App Termination

739 Views Asked by At

I support Live Activities in my app, and am unable to dismiss Live Activities when the app gets closed from the background. I understand that I can send an update from the backend but am unsure how to determine when the app gets terminated in order to send it.

Currently, I subscribe to the willTerminateNotification notification in order to perform actions when the app gets terminated. This gets triggered when the app is terminated in the foreground. However, if it gets terminated from the background, it does not get triggered and my Live Activity stays after the app gets closed. How can I prevent this from happening?

1

There are 1 best solutions below

0
On
// To kill the live activity immediately:
await liveActivity.end(nil, dismissalPolicy: .immediate)