I'm currently collecting real-time heart rate data using HKWorkoutSession. I want to track when the Apple Watch is physically removed from the user's wrist during an active workout.
However, I've noticed that workoutBuilder(_:didCollectDataOf:) continues to be called even after the watch is removed from the wrist.
Is there a way to detect when the Apple Watch is removed from the wrist during an active HKWorkoutSession? Or is this tracking not possible through the HealthKit framework?
Any guidance or alternative approaches would be appreciated.
There is no public API for wrist detection at real time. For non-real-time detection, here is what we have:
-
LAPolicy.deviceOwnerAuthenticationWithWristDetection, which was introduced in watchOS 9. Note that an evaluation failure can be that the watch is on the wrist but the user hasn't entered the correct passcode, which is different from the watch not being on the wrist.
-
SRWristDetection, if you are using SensorKit.
I won't say that HealthKit's delivering heart rate samples after the watch being removed from the wrist is expected – That's probably just a result that the system isn't really sure if the watch is on the wrist or not. I’d suggest that you file a feedback report against that – If you do so, please share your report ID here.
Best,
——
Ziqiao Chen
Worldwide Developer Relations.