How can I detect with watch os when iOS app is closed? I use swift and watchConnectivity.
Also I use swiftUI
There is a method as such
applicationWillTerminate(_:)
*Note By Dávid Pásztor - You will only have 5 seconds to get your message to the watch or it will not work, so make sure the message you send to the watch will be small and fast.
This method will detect that the application is being closed and will be cleared from memory. You can then add some connectivity to notify the watch.
Documentation Here: https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623111-applicationwillterminate
Alternatively, if you want to simply notify the watch whenever the app goes to background, aka goes inactive you can use this method.
applicationWillResignActive(_ application: UIApplication)
Documentation here: https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622950-applicationwillresignactive
If you are using SwiftUI
SceneDelegate.swift :
func sceneDidDisconnect(_ scene: UIScene) {
sendMessageToWatch()
}