void Awake() { //dropdown.ClearOptions(); List <string> opts = new List <string>(); for (int i = 0; i <= (int)HKDataType.HKQuantityTypeIdentifierUVExposure; i++) { HKDataType dataType = (HKDataType)i; opts.Add(HealthKitDataTypes.GetIdentifier(dataType)); } opts.Add("———"); for (int i = (int)HKDataType.HKCharacteristicTypeIdentifierBiologicalSex; i <= (int)HKDataType.HKCharacteristicTypeIdentifierWheelchairUse; i++) { HKDataType dataType = (HKDataType)i; opts.Add(HealthKitDataTypes.GetIdentifier(dataType)); } opts.Add("———"); for (int i = (int)HKDataType.HKCorrelationTypeIdentifierBloodPressure; i <= (int)HKDataType.HKCorrelationTypeIdentifierFood; i++) { HKDataType dataType = (HKDataType)i; opts.Add(HealthKitDataTypes.GetIdentifier(dataType)); } opts.Add("———"); opts.Add(HealthKitDataTypes.GetIdentifier(HKDataType.HKWorkoutTypeIdentifier)); //dropdown.AddOptions(opts); }
// reading a Characteristic private void ReadCharacteristic(HKDataType dataType) { string typeName = HealthKitDataTypes.GetIdentifier(dataType); Debug.LogFormat("reading {0}", typeName); this.healthStore.ReadCharacteristic(dataType, delegate(Characteristic characteristic) { Debug.Log("FINISHED"); string text = string.Format("{0} = {1}", dataType, characteristic); this.resultsLabel.text = text; // all done reading = false; }); }
// A basic example of reading Quantity data. private void ReadQuantityData(HKDataType dataType, DateTimeOffset start, DateTimeOffset end) { string typeName = HealthKitDataTypes.GetIdentifier(dataType); Debug.LogFormat("reading {0} from {1} to {2}", typeName, start, end); double sum = 0; this.healthStore.ReadQuantitySamples(dataType, start, end, delegate(List <QuantitySample> samples) { if (samples.Count > 0) { Debug.Log("found " + samples.Count + " samples"); bool cumulative = (samples[0].quantityType == QuantityType.cumulative); string text = ""; foreach (QuantitySample sample in samples) { Debug.Log(" - " + sample); if (cumulative) { sum += Convert.ToInt32(sample.quantity.doubleValue); } else { text = text + "- " + sample + "\n"; } } if (cumulative) { if (sum > 0) { this.resultsLabel.text = typeName + ":" + sum; } } else { this.resultsLabel.text = text; } } else { Debug.Log("found no samples"); } // all done reading = false; }); }