Ways to export your iOS health data (2023) 💾
As it turns out, programmatically accessing health data from your own iPhone can still be a headache in 2023.
I recently wanted to integrate access for an automation on my website around my daily movement, and I found it to take longer than expected.
Ultimately, I found three ways of accessing this data:
- using the Shortcuts app
- modifying your own, native iOS app from a boilerplate Xcode project that uses the HealthKit API, or
- manually exporting all of your health data from the iOS Health app itself.
The built-in Shortcuts iOS app is a great way to automate tasks on your iPhone, and accessing heath data happens to work here too.
You can start by creating the shortcut either in the Shortcuts tab or Automation tab of the app, depending on whether you want this to run automatically on a schedule or not.
As far as the shortcut itself goes, you can use the Find All Health Samples Where action to retrieve the data you want.
As you can see above, once you've selected the Find All Health Samples action, you can filter for the start/end dates of the data, the source of the data, the units of the data, and the data type itself.
Afterwards, you can use the Calculate Statistics action to calculate the Sum, for example, of the data you've retrieved for the date range.
Finally you can export the data, eg. email the JSON to yourself, integrate with a shell script over SSH, etc.
As a reminder, you can have this Shortcut run as an automation or on-demand depending on your use-case.
Native iOS app
If you want the most flexibility and can code, this is a good option.
You'll want to glance at the Apple HealthKit API (opens in a new tab) to get a sense of what you'll be using to read and transform your data.
I used Apple's Mobility Health App (opens in a new tab) sample project as a starting point before integrating my database and accessing the specific data points I wanted.
In my case, I wanted to read the following data points:
- Distance walked/ran
- Workout data
I also wanted to be able to aggregate data points over a custom time period.
And because this is your own app, you can set it to run at any frequency you want, upload the data to your own database or as a JSON file, seamlessly integrate with your own APIs etc.
Export from iOS Health app
This option is the least practical/flexible depending on your use-case. If you want all the data once on a non-recurring basis, then this could work well.
Simply put, you can access this feature in the Health app by navigating to you profile, then scrolling down to the bottom of the screen, past the Features and Privacy sections, and tapping on Export All Health Data.
This'll take awhile depending on how much data you have, but once it's done, you'll have an XML file with all of your health data.
See the official Apple documentation (opens in a new tab) for more details.
Last Updated: Mon May 29 2023
Looking for more posts?
My Monthly 4-1-1
Tech-centric newsletter with 4 thoughts, 1 personal win, and 1 hack