RAM
RAM

Reputation: 214

HKWorkoutSessionDelegate Not called

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.

Upvotes: 5

Views: 656

Answers (2)

lewis
lewis

Reputation: 3202

I've seen this a few times (not enough to recreate or anything).

I think restarting Xcode and the Simulator helps.

Upvotes: 2

BHendricks
BHendricks

Reputation: 4493

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.

Upvotes: 1

Related Questions