I have conformed to my WorkoutSessionManagerDelegate
and have attempted to update the UI using those protocol methods but nothing in the update function is getting printed or displayed.
My setup requires initialization using context
and I need to add code to update the WorkoutSessionManager
when the context
eventually changes.
How should I update the WorkoutSessionManager
when the context
eventually changes?
DashboardController.swift
class DashboardController: WKInterfaceController, WorkoutSessionManagerDelegate {
// IBOutlets
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
addMenuItemWithItemIcon(.Accept, title: "Save", action: #selector(DashboardController.saveSession))
if context is WorkoutSessionContext {
WorkoutSessionManager.sharedManager(context as! WorkoutSessionContext)
} else {
print("Context is not WorkoutSessionContext")
}
}
func saveSession() {
WorkoutSessionManager.sharedManager!.stopWorkoutAndSave()
}
func workoutSessionManager(workoutSessionManager: WorkoutSessionManager, didUpdateActiveEnergyQuantity activeEnergyQuantity: HKQuantity) {
// nothing in this function is getting printed or displayed
caloriesLabel.setText("\((activeEnergyQuantity.doubleValueForUnit(workoutSessionManager.energyUnit)))")
print("\(WorkoutSessionManager.sharedManager?.energyUnit)")
print("testing print line")
}
WorkoutsController.swift
@IBAction func startWalkingButton() {
print("Walking start button pressed")
presentControllerWithName("Dashboard", context: sessionContext)
WorkoutSessionManager.sharedManager!.startWorkout(.WalkingButton)
// no code-completion
}