I want to update or end a Live Activity when the application is terminated, but those functions are async, and anything inside Task{ } is not get called in the applicationWillTerminate(_) function.
func applicationWillTerminate(_ application: UIApplication) {
Task {
if #available(iOS 16.2, *) {
await LiveActivityManager.cancelAllRunningActivies()
}
}
}
I have tried passing a group user default to the live activity, and live activity uses a timer to check the new value for every seconds, but timer on live activity is not get called.
Is there any way to update the live activity when the application is about to be terminated?
This works for me: https://developer.apple.com/forums/thread/732418
Just remember to use
Task.detachedif the entire class is marked with@MainActor, otherwise anything inside the task will not be execute.