简体   繁体   中英

watchOS: How to use HKWorkoutSession without heart rate sensor

I am working on a fitness app where for now I don't want to gain any data through HealthKit. Actually, keeping my app in the background via HKWorkoutSession was the only thing which forced me to use HealtKit for now.

The problem which I have is that heart rate sensor is running when I stop a workout for ~30sec and sometimes he doesn't want to turn off even after this time. I noticed that for example, Strava app has an active workout session when running and he doesn't turn on heart LEDs when it's active, paused or stopped which is a behavior which I would like to achieve as well but after many tries with different HKWorkoutConfiguration I couldn't.

For example:

    let workoutConfiguration = HKWorkoutConfiguration()
    workoutConfiguration.activityType = .running
    workoutConfiguration.locationType = .unknown

I double checked that I don't reuse previous session or the don't have active session.

For above configuration, the heart rate LEDs are disabled when workout session is active but when I stop it, they glow and usually go out after 30 seconds (except the cases when they don't want to turn off and I don't have any steps to reproduce, for me it looks totally randomly)

Did anyone use HKWorkoutConfiguration with totally disabled heart rate or faced some issues when the heart rate sensor didn't want to turn off?

Apple Watch automatically performs a heart rate scan at the end of the workout, and periodically every 10-12 minutes while you're wearing the watch (there might be more variance possibly related to movement). I wouldn't worry about it too much, but if you are concerned that your app is causing the heart rate monitor to activate just check the watch face for the workout in progress icon. If it's there then perhaps your app has not ended the workout session correctly.

From the document :

The session finetunes Apple Watch's sensors for the specified activity. All workout sessions generate high-frequency heart rate samples; however, an outdoor cycling activity generates accurate location data, while an indoor cycling activity does not.

All workout sessions generate high-frequency heart rate samples

We can't disable HR sensor because it is a key factor to identify the workout's calories burned. System will control this sensor when it can run or stop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM