In Apple's sample project SimpleWatchConnectivity https://developer.apple.com/documentation/watchconnectivity/using_watch_connectivity_to_communicate_between_your_apple_watch_app_and_iphone_app
there is a comment saying:
If I do need to defer completeBackgroundTasks, then I think it would make sense for the WC receipt functions like func session(_ session: WCSession, didReceiveMessage message: [String : Any]) to provide us a completion handler so WC can do this awkward background task handling for us.
SO post: https://stackoverflow.com/q/67218792/1921002
there is a comment saying:
My question is: Is this always the case for timing the call on completeBackgroundTasks (KVO on hasContentPending/activation)? Shouldn't I try to defer completeBackgroundTasks until I have done all the work that normally happens when I receive data over WatchConnectivity?WKWatchConnectivityRefreshBackgroundTask should be completed – Otherwise they will keep consuming the background executing time and eventually causes an app crash. The timing to complete the tasks is when the current WCSession turns to not .activated or hasContentPending flipped to false (see completeBackgroundTasks), so KVO is set up here to observe the changes if the two properties...
If I do need to defer completeBackgroundTasks, then I think it would make sense for the WC receipt functions like func session(_ session: WCSession, didReceiveMessage message: [String : Any]) to provide us a completion handler so WC can do this awkward background task handling for us.
SO post: https://stackoverflow.com/q/67218792/1921002