Tell me how to access medications data in HealthKit
Asked on 06/15/2025
1 search
To access medications data in HealthKit, you can use the new Medications API introduced in the session "Meet the HealthKit Medications API" at WWDC 2025. Here's a brief overview of how you can work with this API:
-
Authorization: First, you need to request permission from the user to read and share their medications data. This is done using the HealthKit object authorization API. Once authorized, your app can access medications and their dose events.
-
Data Representation: Medications are represented by the
HKUserAnnotatedMedication
object, and dose events are represented byHKMedicationDoseEvent
. These objects allow you to fetch and manage medications and their associated dose events. -
Fetching Data: Use the
HKUserAnnotatedMedicationQueryDescriptor
andHKUserAnnotatedMedicationQuery
to fetch medications data. You can query for both active and archived medications without needing a predicate or limit. -
Handling Dose Events: Dose events are tied to medications and can be fetched using sample queries, anchored object queries, and observer queries. You can use predicates to filter dose events by medication or log status.
-
Sample App: The session also provides a sample app that demonstrates how to incorporate medications and dose event data from HealthKit. This app shows how to view dose events and log side effects for medications.
For more detailed information, you can refer to the session Meet the HealthKit Medications API (02:12) which provides an overview of the Medications API.