I am trying to add a function applicationWillTerminate()
in my independent watchOS app. With searching from the internet, I found that you can find application life cycle function delegates with using WKExtensionDelegate
. But I am unable to find any function or method to detect that app is going to kill. So my main concern is to find a method that will called before independent watchOS app is terminated.
import Foundation
import SwiftUI
import WatchKit
final class ExtensionDelegate: NSObject, ObservableObject, WKExtensionDelegate {
func applicationDidFinishLaunching() {
NSLog("App launched")
}
func applicationWillTerminate() {
NSLog("App will terminate")
// trying to call this function but is not declared WKExtensionDelegate
}
func applicationDidEnterBackground() {
NSLog("App deactivated")
NotificationCenter.default.post(name: .appDeactivated, object: nil)
}
}