Custom Exported Workout missing workoutPlan identifier / Metadata only on the very first app launch/install

Hello everyone,

I am experiencing a strange issue regarding retrieving a custom tracking identifier (workoutPlan identifier) from a custom exported workout that has been imported via HealthKit.

The Issue:

  • First Fresh Install: When the app is installed for the first time and initialized, it fails to load/fetch the workout plan ID from the imported workout.

  • Subsequent Launches / Re-installs: If I close and relaunch the app, the app successfully fetches the workout plan ID from HealthKit with absolutely no problems.

Has anyone found a clean way to handle this without forcing a manual user refresh or an awkward delay/retry mechanism on the first launch?

Any insight, workarounds, or best practices would be greatly appreciated!

Environment: iOS 17+, Swift, HealthKit

I am wondering if that is related to the access authorization. When the issue happened, did you check if your app has the right authorization? Also, is it that you can retrieve the imported workout successfully, but theWorkout.workoutPlan returns nil?

To access the workout data, you need the HealthKit authorization (requestAuthorization(toShare:read:)). I am not sure if the WorkoutKit authorization (requestAuthorization()) is also needed in your case, but it may be worth a try, if theWorkout is valid but theWorkout.workoutPlan is nil.

I am also wondering if that is because HealthKit needs some time to synchronize something with Cloud in the first installation. If that is the case, the issue should go away after the synchronization is done, without the need of re-launching / re-installing the app.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Custom Exported Workout missing workoutPlan identifier / Metadata only on the very first app launch/install
 
 
Q