πŸŽ‰ Launch Special 90% off: Get lifetime access to my latest Mandarin-Chinese tool!Learn more β†’

Gabriel Uribe

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.

Link to this headingShortcuts

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.

Link to this headingNative 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 to get a sense of what you'll be using to read and transform your data.

I used Apple's Mobility Health App 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:

  • Steps
  • 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.

Link to this headingExport 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 for more details.

Last Updated: Mon May 29 2023

Link to this headingRelated

Link to this headingLooking for more posts?

Looking for a full-stack Next.js/iOS/visionOS developer for your project? Email us at hello@skyporch.co.