Has anyone had success using the HKWorkoutRouteBuilder in conjunction with the new iOS support for HKLiveWorkoutBuilder?
I was running my watchOS code that worked now brought over to iOS and when I call insertRouteData the function never returns. This happens for both the legacy and closure based block patterns.
private var workoutSession: HKWorkoutSession?
private var workoutBuilder: HKLiveWorkoutBuilder?
private var serviceSession: CLServiceSession?
private var workoutRouteBuilder: HKWorkoutRouteBuilder?
private func startRouteBuilder() {
Task { @MainActor in
self.serviceSession = CLServiceSession(authorization: .whenInUse)
self.workoutRouteBuilder = self.workoutBuilder?.seriesBuilder(for: .workoutRoute()) as? HKWorkoutRouteBuilder
self.locationUpdateTask = Task {
do {
for try await update in CLLocationUpdate.liveUpdates(.fitness) {
if let location = update.location {
self.logger.notice(#function, metadata: [
"location": .stringConvertible(location)
])
try await self.workoutRouteBuilder?.insertRouteData([location])
self.logger.notice("Added location")
}
}
} catch {
self.logger.error(#function, metadata: [
"error": .stringConvertible(error.localizedDescription)
])
}
}
}
}
I did also try CLLocationManager API with delegate which is what my current watch code uses (a bit old). Same issue.
Here is what I've found so far:
- If the workout session is not running, and if the builder hasn't started collection yet, inserting route data works just fine
- I've tried different swift language modes, flipped from main actor to non isolated project settings (Xcode 26)
- Modified Apple's sample code and added location route building to that and reproduced the error, modified sample attached to feedback
This issue was identified against Xcode 26 beta 2 and iPhone 16 Pro simulator. Works as expected on my iPhone 13 Pro beta 2.
FB18603581 - HealthKit: HKWorkoutRouteBuilder insert call within CLLocationUpdate task never returns