WKInterfaceController deinit not called when Workout Session is running

Let me explain my situation:

  • I have a controller that I present as a "model" view
  • I start a workoutSession when a certain event happens
  • The user preses what in my case is called "close". The back button on the top left.
  • The view dismisses as expected
  • The workoutSession is NOT ended

So I tried to check in my didDeactivate() if a session is started, then end it. That the problem, didDeactivate is called even when the context menu is activated.

deinit doesnt seem to be called when I dismiss the view, Even waited long enough hopeing the OS would eventually deinit the controller.

I also dont want to wait for it to deinit. I want to preferably present an alert controller asking the user to save their workout, or worst case, just end the workout.

Replies

Mmm maybe your workoutSession retains your controller preventing its deallocation...

Try setting workoutSession.delegate = null on didDeactivate and reset to self on willActivate.

Ahhhhh Apple!


So I need to end my workoutSession and restart it even when I'm jsut accessing the context menu, jsut so I actually end it when I really need it (ie when the view is ACTUALLY dismissed)

No, try removing the delegate (workoutSession.delegate = null).

Tried it but with no result.. my deinit is not being called after I close my view.


override func didDeactivate() {

workoutSession.delegate = nil

}


deinit {

print("deinit")

}

Hey,


I'm sitll not able to deinit when a workout session is running. I want to end the session and remove the delegate in the deinit but thats not called when a session is running. If no session is running then it gets called as expected.


Basically I need to stop a timer and end a workout session when the user dismisses a modal view using the title (top-left)


On a side note: I don't think DidDeactivate() should be called everytime you present the context menu or such. Otherwise it behaves no differently than didDisappear()


Xcode 8 Beta 4


Additional Note:

My workoutSession is a singleton created once in my Constants class as a static variable.

static var workoutSession: HKWorkoutSession!

Filled a radar as I think this is a critical bug: #27757363


Would love it if someone could help elevate the priority if this is indeed an issue. Would be great to have this fixed in WatchOS 3