Hi @Ziqiao Chen and everyone,
Thank you @simonfromhelix for reviving this thread.
@Ziqiao Chen — I tested the frontmost app state approach as you
suggested. Sharing the full results here in case they're useful.
== Test Setup ==
Disabled HKWorkoutSession entirely (no workout session started)
Used only HKAnchoredObjectQuery for heart rate sampling
Set Return to Clock → PowerNap (per-app Custom) → "After 1 Hour"
Ran the app, then lowered my wrist to simulate a real nap scenario
== Results ==
With Xcode debugger attached:
HR sampling worked great (~5 second intervals), continuous
and stable
This initially gave me hope!
Without Xcode debugger (real-world scenario):
The app was terminated by the system within ~10 minutes,
even with Return to Clock set to 1 hour for this specific app
After lowering my wrist, the screen turned off and the app
was suspended/killed shortly after
Zero heart rate samples were collected
The Xcode debugger appears to elevate the app's priority,
masking the real behavior
Digital Crown:
Pressing the Crown navigates away and HR sampling stops
immediately
For a sleep app, users will inevitably press this accidentally
while napping
Activity Rings (positive!):
Confirmed: no workout record created, Activity Rings unaffected
This is exactly what we'd want — if only the app could stay
alive
I hope the test results above are also helpful for anyone
with similar requirements.
== Where this leaves me ==
@Ziqiao Chen — given that frontmost doesn't survive real sleep
conditions, and there's no way to avoid Activity Rings with
HKWorkoutSession (as you confirmed), I'd love your guidance:
What would be the recommended technical approach for an app that
needs real-time heart rate sampling (every few seconds) during
user-initiated sessions of 15-60 minutes?
I've filed FB22115959 requesting an API for this use case, and I'm
happy to provide additional technical details through whichever
channel you'd recommend.
Thank you again for your time. This thread has been incredibly
valuable, and I hope the test data above helps other developers
in similar situations.
Topic:
App & System Services
SubTopic:
Health & Fitness
Tags: