- Make using HealthKit to a project easy.
- Enable easy integration for health data.
- Provide an Open Source project for the iOS open source community.
- Help others learn about HealthKit.
HealthHub is available through Swift Package Manager, either via Xcode or in Package.swift:
.package(url: "https://github.com/matybrennan/HealthHub", from: "3.0.0"),
Package version "2.4.0" and above requires iOS17 and above in project
Add health kit in capabilities through project in "Capabilities"
Add below code to your info.plist
<key>NSHealthShareUsageDescription</key>
<string>Health want to read your health data</string>
<key>NSHealthUpdateUsageDescription</key>
<string>Health wants to write your progress to health store</string>
The main driver that contains all the business logic is HealthHubManager
which can be injected into your services with HealthHubManagerProtocol
The HealthHubManager
contains all the services below
@StateObject private var hub = HealthHubManager()
or
let hub = HealthHubManager()
let configuration = tracker.configuration
Alternatively is you just need a single service you could just inject the protocol needed
let configuration = ConfigurationService()
MyService -> init(configuration: ConfigurationServiceProtocol)
let myService = MyService(configuration: configuration)
- requestingAuthorization
- presenting healthKit app
var configuration: ConfigurationServiceProtocol
let hub = HealthHubManager()
hub.healthHandler.updateState(.idle)
hub.healthHandler.$state.sink { state in ... }
healthHandler = HealthHandler()
- biologicalSex
- bloodType
- dateOfBirth
- skinType
- isWheelChairUser
var characteristics: CharacteristicServiceProtocol
The ActivityManager
contains all the services below and can be injected into your services with ActivityManagerProtocol
if you just need this service
let activityManager = ActivityManager()
let activeEnergy = activityManager.activeEnergy
or using HealthHubManager
let hub = HealthHubManager()
let activeEnergy = hub.activityManager.activeEnergy
Split into sections to gather data based on timeIntervals
- today, thisWeek, betweenTime
var activeEnergy: ActiveEnergyServiceProtocol
- func steps(fromStepsType type: StepsType)
- Will retrieve results in steps (lastHour, today, thisWeek, betweenTimePreference)
- func reset(type: StepsType)
- Will remove all results in stepType type selected (lastHour, today, thisWeek, betweenTimePreference)
var steps: StepsServiceProtocol
- saveWorkoutItem
- workouts
- today, thisWeek, all
var workout: WorkoutManagerProtocol
- basalBodyTemperature & saveBasalBodyTemperature(_: model, _:extra)
- bodyFatPercentage & saveBodyFatPercentage(_: model, _:extra)
- bodyMassIndex & saveBodyMassIndex(_: model, _:extra)
- bodyTemperature & saBeBodyTemperature(_: model, _:extra)
- electrodermalActivity & saveElectrodermalActivity(_: model, _:extra)
- height & saveHeight(_: model, _:extra)
- leanBodyMass & saveLeanBodyMass(_: model, _:extra)
- waistCircumference & saveWaistCircumference(_: model, _:extra)
- weight & saveweight(_: model, _:extra)
- wristTemperature
var bodyMeasurements: BodyMeasurementsServiceProtocol
- abdominalCramps & saveAbdominalCramps(_: model, _:extra)
- bloating & saveBloating(_: model, _:extra)
- breastPain & saveBreastPain(_: model, _:extra)
- cervicalMucusQuality & saveCervicalMucusQuality(_: model, _:extra)
- menstruation & saveMenstruation(_: model, _:extra)
- moodChanges & saveMoodChanges(_: model, _:extra)
- ovulation & saveOvulation(_: model, _:extra)
- pregnancyTestResult & savePregnancyTestResult(_: model, _:extra)
- progesteroneTestResult & saveProgesteroneTestResult(_: model, _:extra)
- sexualActivity & saveSexualActivity(_: model, _:extra)
- spotting & saveSpotting(_: model, _:extra)
- vaginalDryness & saveVaginalDryness(_: model, _:extra)
var cycleTracking: CycleTrackingServiceProtocol
- heartRate (see reference below)
- atrialFibrillation
- bloodPressure & saveBloodPressure(_: model, _:extra)
- cardioFitness & saveCardioFitness(_: model, _:extra)
- cardioRecovery & saveCardioRecovery(_: model, _:extra)
- peripheralPerfusionIndex & savePeripheralPerfusionIndex(_: model, _:extra)
var heart: HeartManagerProtocol
- func heartRate(fromHeartRateType type: HeartRateType)
- Will retrieve results in heartRate (current, today, thisWeek, allTime, betweenTimePreference)
- func reset(type: HeartRateType)
- Will remove all results in heartRate type selected (current, today, thisWeek, allTime, betweenTimePreference)
var heartRate: HeartRateService
- mindfulActivity & saveMindful(_: model, _:extra)
- sleep & saveSleep(_: model, _:extra)
- timeInDaylight & saveTimeInDaylight(_: model, _:extra)
var mentalWellbeing: MentalWellbeingServiceProtocol
- cardioFitness & saveCardioFitness(_: model, _:extra)
- doubleSupportTime & saveDoubleSupportTime(_: model, _:extra)
- groundContactTime & saveGroundContactTime(_: model, _:extra)
- runningStrideLength & saveRunningStrideLength(_: model, _:extra)
- sixMinuteWalk & saveSixMinuteWalk(_: model, _:extra)
- stairSpeedDown & saveStairSpeedDown(_: model, _:extra)
- stairSpeedUp & saveStairSpeedUp(_: model, _:extra)
- verticalOscillation & saveVerticalOscillation(_: model, _:extra)
- walkingAsymmetry
- walkingSpeed & saveWalkingSpeed(_: model)
- walkingSteadiness
- walkingStepLength & saveWalkingStepLength(_: model)
var mobility: MobilityServiceProtocol
- nutrition(_ :type) & saveNutrition(_: model, _:extra)
Types vary based on:
- macronutrients
- minerals
- ultratrace minerals
- vitamins
- hydration
- caffeine
var nutrition: NutritionServiceProtocol
- bloodOxygen & saveBloodOxygen(_: model, _:extra)
- forcedExpiratoryVolume & saveForcedExpiratoryVolume(_: model, _:extra)
- forcedVitalCapacity & saveForcedVitalCapacity(_: model, _:extra)
- inhalerUsage & saveInhalerUsage(_: model, _:extra)
- peakExpiratoryFlowRate & savePeakExpiratoryFlowRate(_: model, _:extra)
- respiratoryRate & saveRespiratoryRate(_: model, _:extra)
- sixMinuteWalk & saveSixMinuteWalk(_: model, _:extra)
var respiratory: RespiratoryServiceProtocol
- sleep & saveSleep(_: model, _:extra)
var sleep: SleepServiceProtocol
- appetiteChanges & saveAppetiteChanges(_: model, _:extra)
- symptom(: type) & saveSymptom(: model, _:extra)
Symptom types include:
- abdominalCramps, acne, bladderIncontinence, bloating, bodyAndMuscleAche, breastPain, chestTightnessOrPain, chills, congestion, constipation, coughing, diarrhea, dizziness, drySkin, fainting, fatigue, fever, hairLoss, headache, hotFlushes, loss of smell, loss of taste, lowerBackPain, memoryLapse, moodChanges, nausea, nightSweats, pelvicPain, rapidPoundingOrFlutteringHeartbeat, runnyNose, shortnessOfBreath, skippedHeartbeat, sleepChanges, soreThroat, vaginalDryness, vomiting, wheezing
var symptoms: SymptomsServiceProtocol
- bloodGlucose & saveBloodGlucose(_: model, _:extra)
- bloodOxygen & saveBloodOxygen(_: model, _:extra)
- bloodPressure & saveBloodPressure(_: model, _:extra)
- bodyTemperature & saveBodyTemperature_: model, _:extra)
- menstruation & saveMenstruation(_: model, _:extra)
- respiratoryRate & saveRespiratoryRate(_: model, _:extra)
var vitals: VitalsServiceProtocol
- alcoholConsumption & saveAlcoholConsumption(_: model, _:extra)
- bloodAlcoholContent & saveBloodAlcoholContent(_: model, _:extra)
- bloodGlucose & saveBloodGlucose(_: model, _:extra)
- handWashing & saveHandWashing(_: model, _:extra)
- inhalerUsage & saveInhalerUsage(_: model, _:extra)
- insulinDelivery & saveInsulinDelivery(_: model, _:extra)
- numberOfTimesFallen & saveNumberOfTimesFallen(_: model, _:extra)
- sexualActivity & saveSexualActivity(_: model, _:extra)
- toothBrushing & saveToothBrushing(_: model, _:extra)
- timeInDaylight & saveTimeInDaylight(_: model, _:extra)
- uvExposure & saveUvExposure(_: model, _:extra)
- waterTemperature & saveWaterTemperature(_: model, _:extra)
var otherData: OtherDataServiceProtocol
Have a question or an issue about HealthHub? Create an issue!
Interested in contributing to HealthHub? Branch off and create a PR
Add your app to the list of apps using this library and make a pull request.
HealthHub is available under the MIT license.