Requests permission to save and read the specified data types.
- iOS 8.0+
- watchOS 2.0+
A set containing the data types you want to share. This set can contain any concrete subclass of the
HKSampleclass (any of the
HKCorrelationclasses ). If the user grants permission, your app can create and save these data types to the HealthKit store.
A set containing the data types you want to read. This set can contain any concrete subclass of the
HKObjectclass (any of the
HKCorrelationclasses ). If the user grants permission, your app can read these data types from the HealthKit store.
A block that is called after the user finishes responding to the request. This block is passed the following parameters:
A Boolean value that indicates whether the request was processed successfully. This value does not indicate whether permission was actually granted. This parameter is
falseif an error occurred while processing the request; otherwise, it is
An error object. If an error occurred, this object contains information about the error; otherwise, it is set to
HealthKit performs these requests asynchronously. If you call this method with a new data type (a type of data that the user has not previously granted or denied permission for in this app), the system automatically displays the permission form, listing all the requested permissions. After the user has finished responding, this method calls its completion block on a background queue. If the user has already chosen to grant or prohibit access to all of the types specified, the completion is called without prompting the user.
Each data type has two separate permissions, one to read the data and one to share the data. Typically, you want to request permission for all the data your app needs at one time.
Customize the messages displayed on the permissions sheet by setting the following keys in your app’s
info file. Set the
NSHealth key to customize the message for reading data. Set the
NSHealth key to customize the message for writing data. These keys are required for apps that read or write HealthKit data. For more information, see iOS Keys in Information Property List Key Reference.
After users have set the permissions for your app, they can always change them using either the Settings or the Health app. Your app appears in the Health app’s Sources tab, even if the user did not allow permission to read or share data.