Пример #1
0
        public override void WillActivate()
        {
            base.WillActivate();
            ResetUI();
            if (!HKHealthStore.IsHealthDataAvailable)
            {
                return;
            }
            // We need to be able to write workouts, so they display as a standalone workout in the Activity app on iPhone.
            // We also need to be able to write Active Energy Burned to write samples to HealthKit to later associating with our app.

            var typesToShare = new NSSet(HKQuantityType.Create(HKQuantityTypeIdentifier.HeartRate), HKQuantityType.Create(HKQuantityTypeIdentifier.ActiveEnergyBurned), HKObjectType.GetWorkoutType());
            var typesToRead  = new NSSet(HKQuantityType.Create(HKQuantityTypeIdentifier.HeartRate), HKQuantityType.Create(HKQuantityTypeIdentifier.ActiveEnergyBurned));

            HealthStore.RequestAuthorizationToShare(typesToShare, typesToRead, (bool success, NSError error) =>
            {
                if (error != null && !success)
                {
                    Console.WriteLine("You didn't allow HealthKit to access these read/write data types. " +
                                      "In your app, try to handle this error gracefully when a user decides not to provide access. " +
                                      $"The error was: {error.LocalizedDescription}. If you're using a simulator, try it on a device.");
                }
            });
            _dangerousHeartRate.Where(v => v > 30.0).Subscribe(
                v => SessionManager.SharedManager.UpdateApplicationContext(
                    new Dictionary <string, object>()
            {
                { "HeartRate", v.ToString() }
            }));
        }
 public void GetUserAuthorizationIfNeeded()
 {
     if (IsHealthDataAvailable)
     {
         HealthStore.RequestAuthorizationToShare(HealthTypesToWrite(),
                                                 HealthTypesToRead(),
                                                 (success, error) => {
             if (!success || error != null)
             {
                 AlertManager.ShowError("Health Data", "Unable to access health data.");
             }
         });
     }
 }
Пример #3
0
        public override void WillActivate()
        {
            // Only proceed if health data is available.
            if (!HKHealthStore.IsHealthDataAvailable)
            {
                return;
            }

            // We need to be able to write workouts, so they display as a standalone workout in the Activity app on iPhone.
            // We also need to be able to write Active Energy Burned to write samples to HealthKit to later associating with our app.

            var typesToShare = new NSSet(HKQuantityType.Create(HKQuantityTypeIdentifier.ActiveEnergyBurned), HKObjectType.GetWorkoutType());
            var typesToRead  = new NSSet(HKQuantityType.Create(HKQuantityTypeIdentifier.ActiveEnergyBurned));

            HealthStore.RequestAuthorizationToShare(typesToShare, typesToRead, (bool success, NSError error) => {
                if (error != null && !success)
                {
                    Console.WriteLine("You didn't allow HealthKit to access these read/write data types. " +
                                      "In your app, try to handle this error gracefully when a user decides not to provide access. " +
                                      $"The error was: {error.LocalizedDescription}. If you're using a simulator, try it on a device.");
                }
            });
        }