Hi Ziqiao, thanks for the response.
I instrumented this further and can now be precise: it's neither an authorization problem nor a nil return. The await on workout.workoutPlan never returns on the first launch after a fresh install. It doesn't throw and doesn't return nil. The task just hangs indefinitely.
What I verified at the moment of the hang:
HealthKit authorization is granted, requestAuthorization(toShare: [], read: [.workoutType()]) completes, and the workout query itself succeeds (I get all my HKWorkout samples back).
WorkoutKit authorization is also granted. I read WorkoutScheduler.shared.authorizationState immediately before the plan reads and it reports .authorized.
After a force-quit and relaunch, the exact same code returns the plans immediately.
Minimal repro (this is essentially Apple's WWDC23 "Customizing workouts with WorkoutKit" sample extended with a fetch. I reproduced the same hang there too, not just in my production app):
let descriptor = HKSampleQueryDescriptor(
predicates: [.workout()],
sortDescriptors: [SortDescriptor(\.endDate, order: .reverse)],
limit: 25)
let workouts = try await descriptor.result(for: healthStore) // ✅ returns 25 workouts
for workout in workouts {
let plan = try? await workout.workoutPlan // ⚠️ hangs forever on first launch
// never reached on first launch
}
Questions:
Is the first-launch hang of HKWorkout.workoutPlan a known issue?
Environment: iOS 17+ deployment target, Swift concurrency, reproduced in the modified Apple sample.
Topic:
App & System Services
SubTopic:
Health & Fitness
Tags: