HKLiveWorkoutBuilder save workouts to HealthKit unexpected timing, unexpected data

Hello, I'm developing a running app on watch os.

The app get heartrate data using HKLiveWorkoutBuilder.

But HKLiveWorkoutBuilder save workouts to HealthKit unexpected timing, unexpected data. It happens even though the application is not running. Its behavior can not be predicted.


This is a screen shot of Health app.

https://www.dropbox.com/s/y1v8vzm0mwksqb4/IMG_0007.png?dl=0


It is quite strange because a I have executed HKWorkoutSession only once. Additionally, I call [_builder discardWorkout] at finish.


This is a xcode project for reproducing the problem.

https://www.dropbox.com/s/mls93oq4loy79u0/SimpleRun.zip?dl=0


This is the InterfaceController.m on apple watch.

https://gist.github.com/Ushio/cf5be41a2b0f52112240ff05c6f84fc0


Is this a bug? Or am I misunderstanding how to use HKLiveWorkoutBuilder ?


Envelopment

  • macOS Mojave 10.14, mac pro Late 2013
  • Xcode 10.1
  • iOS 12.0, iPhone 6 plus
  • Watch OS 5.1.2, Apple Watch Series 2-42mm