partial void ToggleWorkout () { if (IsWorkoutRunning && CurrentWorkoutSession != null) { HealthStore.EndWorkoutSession (CurrentWorkoutSession); IsWorkoutRunning = false; } else { // Begin workout. IsWorkoutRunning = true; // Clear the local Active Energy Burned quantity when beginning a workout session. CurrentActiveEnergyQuantity = HKQuantity.FromQuantity (HKUnit.Kilocalorie, 0.0); CurrentQuery = null; ActiveEnergySamples = new List<HKSample> (); // An indoor walk workout session. There are other activity and location types available to you. // Create a workout configuration var configuration = new HKWorkoutConfiguration { ActivityType = HKWorkoutActivityType.Walking, LocationType = HKWorkoutSessionLocationType.Indoor }; NSError error = null; CurrentWorkoutSession = new HKWorkoutSession (configuration, out error) { Delegate = this }; HealthStore.StartWorkoutSession(CurrentWorkoutSession); } }
public override void HandleWorkoutConfiguration(HKWorkoutConfiguration workoutConfiguration) { WKInterfaceController.ReloadRootPageControllers(new string[] { nameof(WorkoutInterfaceController) }, new NSObject[] { workoutConfiguration }, WKPageOrientation.Vertical, 0); }
partial void ToggleWorkout() { if (IsWorkoutRunning && CurrentWorkoutSession != null) { HealthStore.EndWorkoutSession(CurrentWorkoutSession); IsWorkoutRunning = false; } else { // Begin workout. IsWorkoutRunning = true; // Clear the local Active Energy Burned quantity when beginning a workout session. CurrentActiveEnergyQuantity = HKQuantity.FromQuantity(HKUnit.Kilocalorie, 0.0); CurrentQuery = null; ActiveEnergySamples = new List <HKSample> (); // An indoor walk workout session. There are other activity and location types available to you. // Create a workout configuration var configuration = new HKWorkoutConfiguration { ActivityType = HKWorkoutActivityType.Walking, LocationType = HKWorkoutSessionLocationType.Indoor }; NSError error = null; CurrentWorkoutSession = new HKWorkoutSession(configuration, out error) { Delegate = this }; HealthStore.StartWorkoutSession(CurrentWorkoutSession); } }
partial void DidTapStartButton() { // Create workout configuration var workoutConfiguration = new HKWorkoutConfiguration { ActivityType = this.selectedActivityType.Map(), LocationType = this.selectedLocationType.Map() }; // Pass configuration to next interface controller WKInterfaceController.ReloadRootPageControllers(new[] { nameof(WorkoutInterfaceController) }, new[] { workoutConfiguration }, WKPageOrientation.Vertical, 0); }
private void StartOutdoorRun() { // Create a workout configuration var configuration = new HKWorkoutConfiguration() { ActivityType = HKWorkoutActivityType.Running, LocationType = HKWorkoutSessionLocationType.Outdoor }; // Create workout session // Start workout session NSError error = null; var workoutSession = new HKWorkoutSession(configuration, out error); // Successful? if (error != null) { // Report error to user and return return; } // Create workout session delegate and wire-up events RunDelegate = new WorkoutDelegate(HealthStore, workoutSession); RunDelegate.Failed += () => { System.Diagnostics.Debug.WriteLine("Failed"); }; RunDelegate.Paused += () => { System.Diagnostics.Debug.WriteLine("Paused"); }; RunDelegate.Running += () => { System.Diagnostics.Debug.WriteLine("Running"); }; RunDelegate.Ended += () => { System.Diagnostics.Debug.WriteLine("Ended"); }; // Start session HealthStore.StartWorkoutSession(workoutSession); }
partial void OnToggleWorkout() { if (!IsWorkoutRunning && CurrentWorkoutSession == null) { // Begin workoutt IsWorkoutRunning = true; ToggleWorkoutButton.SetTitle("Rest little Baby");; // Clear the local Active Energy Burned quantity when beginning a workout session CurrentActiveEnergyQuantity = HKQuantity.FromQuantity(HKUnit.Kilocalorie, 0.0); CurrentHeartRate = HKQuantity.FromQuantity(HKUnit.FromString("count/min"), 0.0); CurrentQuery = null; HeartRateQuery = null; ActiveEnergySamples = new List <HKSample>(); HeartRateSamples = new List <HKSample>(); // An indoor walk workout session. There are other activity and location types available to you. // Create a workout configuratio var configuration = new HKWorkoutConfiguration { ActivityType = HKWorkoutActivityType.Walking, // Why not crawling? : LocationType = HKWorkoutSessionLocationType.Indoor }; NSError error = null; CurrentWorkoutSession = new HKWorkoutSession(configuration, out error) { Delegate = this }; HealthStore.StartWorkoutSession(CurrentWorkoutSession); } else { HealthStore.EndWorkoutSession(CurrentWorkoutSession); IsWorkoutRunning = false; ResetUI(); } }
public override void HandleWorkoutConfiguration(HKWorkoutConfiguration workoutConfiguration) { // Create workout session // Start workout session NSError error = null; WorkoutSession = new HKWorkoutSession(workoutConfiguration, out error); // Successful? if (error != null) { // Report error to user and return return; } // Create workout session delegate and wire-up events RunDelegate = new WorkoutDelegate(HealthStore, WorkoutSession); RunDelegate.Failed += () => { System.Diagnostics.Debug.WriteLine("Failed"); }; RunDelegate.Paused += () => { System.Diagnostics.Debug.WriteLine("Paused"); }; RunDelegate.Running += () => { System.Diagnostics.Debug.WriteLine("Running"); }; RunDelegate.Ended += () => { System.Diagnostics.Debug.WriteLine("Ended"); }; // Start session HealthStore.StartWorkoutSession(WorkoutSession); }