I am trying to create a nice user experience for doing workouts on my app using an Apple Watch. I can start an HKWorkoutSession on my watch and stop it fine, in the foreground and in the background.
My problem is that the HKObjectQuery does not seem to stop when the watch app is in the background. To clarify, if I lock the watch and the phone for about 3 minutes during a workout and then try to stop stop the workout from the phone app nothing happens.
Any solutions, or even an explanation as to why would be greatly appreciated.
You need to enable background modes for your WatchKit Extension.
App Programming Guide for watchOS: Leveraging iOS Technologies states:
Now when your app has started a workout on the Apple Watch, it will respond to WatchConnectivity messages in the background.
So, if you have handled the WatchConnectivity message to stop the workout, it will stop.