Saving workout routes on the phone when locked

I'm using HKLiveWorkoutDataSource and HKWorkoutRouteBuilder. The running workouts my app supports can be timed or distance-based, so the user may complete the workout while the phone is locked. In this case, the workout route cannot be saved because HealthKit is locked. To work around this issue, I save route data to the device and listen for UIApplication.protectedDataDidBecomeAvailableNotification to later add the route to the workout.

Note, this is not needed on the watch, just the phone. Is this limitation by design, or is there a better way to handle it?

BTW, thanks for making these APIs available on the phone in iOS 26 and also adding the heart rate zone APIs in 27

Answered by Engineer in 892743022

Are you using an HKWorkoutRouteBuilder retrieved from you HKLiveWorkoutBuilder?

Our recommendation is for you to use seriesBuilder(for:) in the workout builder to initialize your route builder. Then at the time of ending your workout, when calling finishWorkout on HKLiveWorkoutBuilder the route will be saved and added to the workout. No need to finish the route builder.

Are you using an HKWorkoutRouteBuilder retrieved from you HKLiveWorkoutBuilder?

Our recommendation is for you to use seriesBuilder(for:) in the workout builder to initialize your route builder. Then at the time of ending your workout, when calling finishWorkout on HKLiveWorkoutBuilder the route will be saved and added to the workout. No need to finish the route builder.

Yes, I was using seriesBuilder and I don't explicitly finish the route builder, but the route does not get saved if the phone is locked.

Thanks for your response, please file a bug report, and post the FB number here once you do. The specific info you include in your bug report might help our investigation, and filing the bug report allows you to get notified when it is resolved.

Bug Reporting: How and Why? explains how you can open a bug report.

Saving workout routes on the phone when locked
 
 
Q