コード例 #1
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);
            }
        }
コード例 #2
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);
        }
コード例 #3
0
        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();
            }
        }
コード例 #4
0
        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);
        }