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 Awake(NSObject context) { base.Awake(context); // Configure interface objects here. Console.WriteLine("{0} awake with context", this); var workoutConfiguration = context as HKWorkoutConfiguration; if (workoutConfiguration == null) { throw new ArgumentException("The 'context' is not a HKWorkoutConfiguration", nameof(context)); } // create a workout session with the workout configuration NSError error; this.workoutSession = new HKWorkoutSession(workoutConfiguration, out error); if (error == null) { // start a workout session this.workoutSession.Delegate = this; this.healthStoreManager.Start(this.workoutSession); } else { throw new Exception(error.Description ?? "Unknown exception"); } }
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 void SaveWorkout(HKWorkoutSession workoutSession, NSDate startDate, NSDate endDate) { // Create and save a workout sample var configuration = workoutSession.WorkoutConfiguration; var metadata = new HKMetadata { IndoorWorkout = configuration.LocationType == HKWorkoutSessionLocationType.Indoor, }; var workout = HKWorkout.Create(configuration.ActivityType, startDate, endDate, this.workoutEvents.ToArray(), this.TotalBurningEnergyQuantity(), this.TotalDistanceQuantity(), metadata); this.healthStore.SaveObject(workout, (isSuccess, error) => { if (isSuccess) { this.AddSamples(workout, startDate, endDate); } }); }
public void DidChangeToState(HKWorkoutSession workoutSession, HKWorkoutSessionState toState, HKWorkoutSessionState fromState, NSDate date) { DispatchQueue.MainQueue.DispatchAsync(() => { this.HandleWorkoutSessionState(toState, fromState); }); }
public void WorkoutSession(HKWorkoutSession workoutSession, HKWorkoutEvent @event) { DispatchQueue.MainQueue.DispatchAsync(() => { this.healthStoreManager.WorkoutEvents.Add(@event); }); }
public WorkoutDelegate(HKHealthStore healthStore, HKWorkoutSession workoutSession) { // Initialize this.HealthStore = healthStore; this.WorkoutSession = workoutSession; // Attach this delegate to the session workoutSession.Delegate = this; }
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); }
public void DidChangeToState(HKWorkoutSession workoutSession, HKWorkoutSessionState toState, HKWorkoutSessionState fromState, NSDate date) { DispatchQueue.MainQueue.DispatchAsync(delegate { // Take action based on the change in state switch (toState) { case HKWorkoutSessionState.Running: BeginWorkout((DateTime)date); break; case HKWorkoutSessionState.Ended: EndWorkout((DateTime)date); break; default: Console.WriteLine($"Unexpected workout session: {toState}."); break; } }); }
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 DidChangeToState(HKWorkoutSession workoutSession, HKWorkoutSessionState toState, HKWorkoutSessionState fromState, NSDate date) { // Take action based on the change in state switch (toState) { case HKWorkoutSessionState.NotStarted: break; case HKWorkoutSessionState.Paused: RaisePaused(); break; case HKWorkoutSessionState.Running: RaiseRunning(); break; case HKWorkoutSessionState.Ended: RaiseEnded(); break; } }
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); }
public void Resume(HKWorkoutSession workoutSession) { this.healthStore.ResumeWorkoutSession(workoutSession); }
public void Pause(HKWorkoutSession workoutSession) { this.healthStore.PauseWorkoutSession(workoutSession); }
public void End(HKWorkoutSession workoutSession) { this.healthStore.EndWorkoutSession(workoutSession); }
public void Start(HKWorkoutSession workoutSession) { this.healthStore.StartWorkoutSession(workoutSession); }
public void DidFail(HKWorkoutSession workoutSession, NSError error) { Console.WriteLine($"An error occured with the workout session. In your app, try to handle this gracefully. The error was: {error}."); }
public void DidFail (HKWorkoutSession workoutSession, NSError error) { Console.WriteLine ($"An error occured with the workout session. In your app, try to handle this gracefully. The error was: {error}."); }
public void DidChangeToState (HKWorkoutSession workoutSession, HKWorkoutSessionState toState, HKWorkoutSessionState fromState, NSDate date) { DispatchQueue.MainQueue.DispatchAsync (delegate { // Take action based on the change in state switch (toState) { case HKWorkoutSessionState.Running: BeginWorkout ((DateTime)date); break; case HKWorkoutSessionState.Ended: EndWorkout ((DateTime)date); break; default: Console.WriteLine ($"Unexpected workout session: {toState}."); break; } }); }
public override void DidFail(HKWorkoutSession workoutSession, NSError error) { // Handle workout session failing RaiseFailed(); }
public void DidFail(HKWorkoutSession workoutSession, NSError error) { this.StopTimer(); this.workoutSession.Dispose(); Console.WriteLine($"workout session failed with an error: ({error})"); }
public override void DidGenerateEvent(HKWorkoutSession workoutSession, HKWorkoutEvent @event) { base.DidGenerateEvent(workoutSession, @event); }