The native workout app and Sportstracker for example have the ability to pause the workout when a user presses both the digital crown and the side button at the same time, AKA taking a screenshot.
I need something like this but I can't find anything about it in the docs or anywhere else online. For iOS there's the "notificationUIApplicationUserDidTakeScreenshot", but that doesn't work on watchOS.
Anyone know how to do this? Is it publicly available or is this a private API? Did I not look well enough?
I haven't tried this, but with some digging around in the HealthKit docs, it looks like:
You presumably have an HKWorkoutSession
to run your workout anyway, right? And it'll need an HKWorkoutSessionDelegate
handling its state changes and whatnot.
When the user presses the side button and Digital Crown together, your delegate should get a workoutSession(_:didGenerate:)
callback, with the corresponding even having an event type of pauseOrResumeRequest
. (They might or might not also get a screenshot, but that's out of your control.)
You handle the user's request to pause by calling pause(_:)
on the HKHealthStore
.