示例#1
0
        public bool GetStatus()
        {
            var pList                = NSUserDefaults.StandardUserDefaults;
            var isEnabled            = pList.BoolForKey(_userDefaultsKey);
            var isBloodGlucoseStatus = _healthStore.GetAuthorizationStatus(HKQuantityType.Create(HKQuantityTypeIdentifier.BloodGlucose));
            var isInsulinStatus      = _healthStore.GetAuthorizationStatus(HKQuantityType.Create(HKQuantityTypeIdentifier.InsulinDelivery));

            var hasAccessToHealthKit = isBloodGlucoseStatus == HKAuthorizationStatus.SharingAuthorized ||
                                       isInsulinStatus == HKAuthorizationStatus.SharingAuthorized;

            return(isEnabled && hasAccessToHealthKit);
        }
示例#2
0
        void ReactToHealthCarePermissions(bool success, NSError error)
        {
            var access = healthKitStore.GetAuthorizationStatus(HKQuantityType.Create(HKQuantityTypeIdentifier.BodyMass));

            if (access.HasFlag(HKAuthorizationStatus.SharingAuthorized))
            {
                BodyMassModel.Instance.Enabled = true;
            }
            else
            {
                BodyMassModel.Instance.Enabled = false;
            }
            string temp = error.Description;
        }
示例#3
0
        //Note that this will be called on a background thread
        void ReactToHealthCarePermissions(bool success, NSError error)
        {
            /*
             * The success and error arguments specify whether the user interacted
             * with the permissions dialog. This sample doesn't use that information.
             */

            //Instead, the important thing is to confirm that we can write heart-rate data
            var access = healthKitStore.GetAuthorizationStatus(HKObjectType.GetQuantityType(HKQuantityTypeIdentifierKey.HeartRate));

            if (access.HasFlag(HKAuthorizationStatus.SharingAuthorized))
            {
                HeartRateModel.Instance.Enabled = true;
            }
            else
            {
                HeartRateModel.Instance.Enabled = false;
            }
        }
        public Task <List <WeightData> > GetWeigths()
        {
            var weightType = HKQuantityType.Create(HKQuantityTypeIdentifier.BodyMass);

            if (HealthStore.GetAuthorizationStatus(weightType) == HKAuthorizationStatus.SharingAuthorized)
            {
                var completionSource = new TaskCompletionSource <List <WeightData> >();
                FetchMostRecentData(weightType, (QuantityResults, error) =>
                {
                    if (error != null)
                    {
                        //Console.WriteLine("An error occured fetching the user's age information. " +
                        //"In your app, try to handle this gracefully. The error was: {0}", error.LocalizedDescription);
                        completionSource.SetResult(null);
                    }

                    data = new List <WeightData>();
                    if (QuantityResults != null)
                    {
                        results = QuantityResults;
                        for (int i = 0; i < QuantityResults.Count; i++)
                        {
                            WeightData h   = new WeightData();
                            var weightUnit = HKUnit.Gram;
                            h.Value        = ((HKQuantitySample)QuantityResults[i]).Quantity.GetDoubleValue(weightUnit) / 1000f;
                            h.Unit         = "kg";
                            h.Date         = DateUtil.NSDateToDateTime(((HKQuantitySample)QuantityResults[i]).StartDate);
                            data.Add(h);
                        }
                    }
                    completionSource.SetResult(data);
                }, 365 * 2
                                    );
                return(completionSource.Task);
            }
            else
            {
                return(null);
            }
        }
 public override async Task <bool> IsSetup()
 {
     // Lets try and read the date of birth
     return(HealthStore.GetAuthorizationStatus(HKQuantityType.GetQuantityType(HKQuantityTypeIdentifierKey.Height)) == HKAuthorizationStatus.SharingAuthorized);
 }