// Characteristic types /*! @brief Read a characteristic. * @details * @param dataType The datatype to read. * @param handler Called when the function finishes executing. */ public void ReadCharacteristic(HKDataType dataType, ReceivedCharacteristic handler) { this.receivedCharacteristicHandlers[dataType] = handler; string identifier = HealthKitDataTypes.GetIdentifier(dataType); _ReadCharacteristic(identifier); }
private void ReadCorrelation(HKDataType dataType, DateTimeOffset startDate, DateTimeOffset endDate, bool combineSamples) { if (this.IsHealthDataAvailable()) { string identifier = HealthKitDataTypes.GetIdentifier(dataType); _ReadCorrelation(identifier, DateTimeBridge.DateToString(startDate), DateTimeBridge.DateToString(endDate), combineSamples); } else { Debug.LogError("Error: no health data is available. Are you running on an iOS device that supports HealthKit?"); } }
/*! @brief Write a category sample. * @details * @param dataType The datatype to write. * @param value the (integer) value to use to create a sample. * @param startDate The starting date of the sample to write. * @param endDate The ending date of the sample to write. * @param handler Called when the function finishes executing. */ public void WriteCategorySample(HKDataType dataType, int value, DateTimeOffset startDate, DateTimeOffset endDate, WroteSample handler) { this.wroteSampleHandlers[dataType] = handler; if (this.IsHealthDataAvailable()) { string identifier = HealthKitDataTypes.GetIdentifier(dataType); _WriteCategory(identifier, value, DateTimeBridge.DateToString(startDate), DateTimeBridge.DateToString(endDate)); } else { Debug.LogError("Error: no health data is available. Are you running on an iOS device that supports HealthKit?"); } }
private void ReadQuantity(HKDataType dataType, DateTimeOffset startDate, DateTimeOffset endDate, bool combineSamples) { if (this.IsHealthDataAvailable()) { string identifier = HealthKitDataTypes.GetIdentifier(dataType); string startStamp = DateTimeBridge.DateToString(startDate); string endStamp = DateTimeBridge.DateToString(endDate); Debug.LogFormat("reading quantity from:\n-{0} ({1})\nto:\n-{2} ({3})", startDate, startStamp, endDate, endStamp); _ReadQuantity(identifier, startStamp, endStamp, combineSamples); } else { Debug.LogError("Error: no health data is available. Are you running on an iOS device that supports HealthKit?"); } }
/*! @brief returns authorization status for a given datatype. * @details See [HKAuthorizationStatus](https://developer.apple.com/documentation/healthkit/hkauthorizationstatus) in the Apple documentation. * More useful for write permission; will not tell you if the user denies permission to read the data; it will merely appear as if there is no data. * @param dataType the HealthKit datatype to query */ public HKAuthorizationStatus AuthorizationStatusForType(HKDataType dataType) { HKAuthorizationStatus status = HKAuthorizationStatus.NotDetermined; #if UNITY_IOS && !UNITY_EDITOR string identifier = HealthKitDataTypes.GetIdentifier(dataType); try { status = (HKAuthorizationStatus)_AuthorizationStatusForType(identifier); } catch (System.Exception) { Debug.LogErrorFormat("error parsing authorization status: '{0}'", identifier); } #endif return(status); }
private void DrawDataType(HKDataType dataType) { GUILayout.BeginHorizontal(); Dictionary <string, HKNameValuePair> data = obj.data; if (data != null) { string key = HealthKitDataTypes.GetIdentifier(dataType); if (data.ContainsKey(key)) { EditorGUILayout.LabelField(data[key].name, GUILayout.MaxWidth(240)); EditorGUI.BeginChangeCheck(); bool readValue = EditorGUILayout.Toggle(data[key].read, GUILayout.MaxWidth(40)); if (EditorGUI.EndChangeCheck()) { data[key].read = readValue; string saveData = obj.Save(); this.saveDataProperty.stringValue = saveData; } if (!data[key].writable) { GUI.enabled = false; } EditorGUI.BeginChangeCheck(); bool writeValue = EditorGUILayout.Toggle(data[key].write, GUILayout.MaxWidth(40)); if (EditorGUI.EndChangeCheck()) { data[key].write = writeValue; // EditorUtility.SetDirty(prop.serializedObject.targetObject); string saveData = obj.Save(); this.saveDataProperty.stringValue = saveData; } GUI.enabled = true; } else { EditorGUILayout.LabelField(key, GUILayout.MaxWidth(240)); EditorGUILayout.LabelField("ERROR", GUILayout.MaxWidth(80)); } } GUILayout.EndHorizontal(); }