Returns the user’s preferred units for the given quantity types.
- iOS 8.2+
- Mac Catalyst 13.0+
- watchOS 2.0+
A set of
HKQuantityidentifiers. These identifiers represent the quantity types to be examined. Before calling this method, your app must request read or share access to all the types in this set.
A block that this method calls as soon as it finishes looking up the preferred units. This block is passed the following parameters:
If the lookup is successful, this parameter contains a dictionary with
HKQuantityidentifiers for the keys and
HKUnitobjects for the values. The keys match those passed to the
quantityparameter. If an error occurs, this parameter is set to
An error object. This method returns an error if the preferred units are inaccessible or if your app has not yet requested permission to access the quantity types; otherwise, this parameter is set to
This method runs asynchronously. As soon as it finishes looking up the preferred units, it calls the completion block on an anonymous background queue.
By default, the preferred units are based on the device’s current locale. For example, in the US, the preferred units for the
HKQuantity identifier are pounds. Other regions may use kilograms or stones. However, users can change their preferred units in the Health app at any time.
Your app should present HealthKit data using the current preferred units (see the
HKQuantity results identifier for an exception). You should also observe the
HKUser notification, and update the user interface whenever the user changes his or her preferred units.