0

I am using Apple's WatchConnectivity framework to develop an iOS app with a companion WatchOS app.

On iOS side, after I open the app, I need to manually activate the WCSession to communicate with the Apple Watch like this

if ([WCSession isSupported]) {
    self.wcSession = [WCSession defaultSession];
    self.wcSession.delegate = self;
    [self.wcSession activateSession];
}

After I finish all necessary communications between the iPhone and the Apple Watch, I want to deactivate the WCSession since the activation of WCSession is energy consuming. I have looked through the WatchConnectivity API but haven't found a way to deactivate it. I cannot shutdown the connection unless I quit the app on the iPhone and reopen it again.

Is there a way to deactivate the WCSession? Thank you very much.

yuchen
  • 237
  • 1
  • 10
  • What evidence do you have that the active session uses a lot of energy? If you aren't actively transferring data and your app isn't open on the watch I can't see an active session using much energy; the fact that Apple doesn't provide a method of deactivating the session is a very good indicator that it isn't necessary. – Paulw11 Apr 02 '22 at 04:40
  • @Paulw11 I have tested once. I just activated the `WCSession` and did not send a single message. And the result was that the phone got overheated faster, compared to the situation where I just didn't activate the `WCSession` at all. If this connection is not energy consuming, why we need to manually activate it? Apple could just activate it by default. – yuchen Apr 02 '22 at 07:30
  • Activating a WCSession certainly wouldn't use enough energy to make the phone get hot. That is indicative of high cpu use; intensive computation. You can use the energy instrument to see the actual impact of your app and the session. Of course there is a non-zero cost of activating a session, so if a watch application doesn't need to communicate with its iOS counterpart it doesn't need to activate it. There is also the added complication that a user can have multiple watches. – Paulw11 Apr 02 '22 at 12:05
  • The implementation actually multiplexes any number of WCSessions over a single link between the watch and the phone, so whether or not a particular app activates its session probably has no effect on whether or not there is an actual communication session between the watch and phone. – Paulw11 Apr 02 '22 at 12:06
  • @Paulw11 I see, thanks for your detailed explanation. My app itself is very energy comsuing, it will make the phone hot for like 10 minutes. And the activation of a WCSession does accelerate the process a bit. Let us assume a user will use the app for 20 mintues, and he needs to send one message from the watch to the phone at the first minute. In order to do that, we need to activate the WCSession at the beginning, and we have absolutely no way to deactivate the WCSession even we no longer need it for the remaining 19 minutes, is that the case? – yuchen Apr 07 '22 at 02:25
  • 1
    That is the case. Activating a WCSession is a *logical* operation that may or may not have a direct *physical* impact; The communication between the watch and the phone may already be active. You can use the energy instrument to examine your app's energy use in more detail – Paulw11 Apr 07 '22 at 03:50
  • @Paulw11 I see, thanks man. I think this is the answer. You can post this as an answer and I will accept it. – yuchen Apr 07 '22 at 07:43

1 Answers1

0

Thanks to @Paulw11, I think there is no way to deactivate the WCSession once it has been activated.

yuchen
  • 237
  • 1
  • 10