Instance Method


Enables the background delivery of updates.


func enableBackgroundDelivery(for type: HKObjectType, frequency: HKUpdateFrequency, withCompletion completion: @escaping (Bool, Error?) -> Void)



The type of data to observe. This object can be any concrete subclass of the HKObjectType class (any of the classes HKCharacteristicType , HKQuantityType, HKCategoryType, HKWorkoutType or HKCorrelationType).


The maximum frequency of the updates. The system wakes your app from the background at most once per time period specified. For a complete list of valid frequencies, see HKUpdateFrequency.


A block that this method calls as soon as the background delivery is enabled. This block is passed the following parameters:


A Boolean value. This parameter contains true if the background delivery was successfully enabled; otherwise, false.


An error object. If an error occurred, this object contains information about the error; otherwise, it is set to nil.


Call this method to register your app for background updates. HealthKit wakes your app whenever new samples of the specified type are saved to the store. Your app is called at most once per time period defined by the specified frequency.

As soon as your app launches, HealthKit calls the update handler for any observer queries that match the newly saved data. If you plan on supporting background delivery, set up all your observer queries in your app delegate’s application(_:didFinishLaunchingWithOptions:) method. By setting up the queries in application(_:didFinishLaunchingWithOptions:), you ensure that the queries are instantiated and ready to use before HealthKit delivers the updates.

After your observer queries have finished processing the new data, you must call the update’s completion handler. This lets HealthKit know that you have successfully received the background delivery. If you do not call the update’s completion handler, HealthKit continues to attempt to launch your app using a backoff algorithm. If your app fails to respond three times, HealthKit assume your app cannot receive data and stops sending you background updates.

For more information on the background delivery completion handler, see isHealthDataAvailable().

See Also

Managing Background Delivery

enum HKUpdateFrequency

Constants that determine how often the system will launch your app in response to changes to HealthKit data.

func disableBackgroundDelivery(for: HKObjectType, withCompletion: (Bool, Error?) -> Void)

Disables background deliveries of update notifications for the specified data type.

func disableAllBackgroundDelivery(completion: (Bool, Error?) -> Void)

Disables all background deliveries of update notifications.