I am trying to start a workout session using HKWorkoutSession. It is not starting the session.
let workoutConfiguration = HKWorkoutConfiguration()
workoutConfiguration.activityType = .running
workoutConfiguration.locationType = .outdoor
do {
session = try HKWorkoutSession(healthStore: healthStore!, configuration: workoutConfiguration)
session?.delegate = self
session?.startActivity(with: Date())
print((session?.state)!.rawValue)
} catch let error {
print(error)
}
The HKWorkoutSessionDelegate method
func workoutSession(_ workoutSession: HKWorkoutSession, didChangeTo toState: HKWorkoutSessionState, from fromState: HKWorkoutSessionState, date: Date)
Never gets called.
I've seen this a few times (not enough to recreate or anything).
I think restarting Xcode and the Simulator helps.
Are you trying this on simulator? If you are, I'd try on device. If on device, this could be because you haven't accepted HealthKit permissions? Check in Privacy->Health to see if your app has permissions for HealthKit.