Пример #1
0
        protected override IEnumerable <Datum> Poll(CancellationToken cancellationToken)
        {
            List <Datum> data = new List <Datum>();

            NSError error;
            HKBiologicalSexObject biologicalSex = HealthStore.GetBiologicalSex(out error);

            if (error == null)
            {
                if (biologicalSex.BiologicalSex == HKBiologicalSex.Female)
                {
                    data.Add(new BiologicalSexDatum(DateTimeOffset.Now, BiologicalSex.Female));
                }
                else if (biologicalSex.BiologicalSex == HKBiologicalSex.Male)
                {
                    data.Add(new BiologicalSexDatum(DateTimeOffset.Now, BiologicalSex.Male));
                }
                else if (biologicalSex.BiologicalSex == HKBiologicalSex.Other)
                {
                    data.Add(new BiologicalSexDatum(DateTimeOffset.Now, BiologicalSex.Other));
                }
                else
                {
                    throw new Exception("User has not provided -- or has not allowed access to -- their biological sex.");
                }
            }
            else
            {
                throw new Exception("Error reading biological sex:  " + error.Description);
            }

            return(data);
        }
        private void RefreshCharacteristicValue(NSString characteristicTypeKey, HKCharacteristicType characteristicType)
        {
            if (characteristicTypeKey == HKCharacteristicTypeIdentifierKey.BiologicalSex)
            {
                NSError error         = null;
                var     biologicalSex = HealthStore.GetBiologicalSex(out error);
                if (error == null)
                {
                    DispatchQueue.MainQueue.DispatchAsync(() => {
                        var dataStore = StateDispatcher <HealthState> .State;

                        HealthStateMutator.MutateBiologicalSex(
                            dataStore, () => GetDisplayableBiologicalSex(biologicalSex.BiologicalSex));

                        StateDispatcher <HealthState> .Refresh();
                    });
                }
            }
        }