<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: 13.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKHealthStore/enableBackgroundDelivery(for:frequency:withCompletion:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKHealthStore(im)enableBackgroundDeliveryForType:frequency:withCompletion:"
  },
  "title" : "enableBackgroundDelivery(for:frequency:withCompletion:)"
}
-->

# enableBackgroundDelivery(for:frequency:withCompletion:)

Enables the delivery of updates to an app running in the background.

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

## Parameters

`type`

The type of data to observe. This object can be a [`HKCharacteristicType`](/documentation/HealthKit/HKCharacteristicType) , [`HKQuantityType`](/documentation/HealthKit/HKQuantityType), [`HKCategoryType`](/documentation/HealthKit/HKCategoryType), or [`HKWorkoutType`](/documentation/HealthKit/HKWorkoutType). [`HKCorrelationType`](/documentation/HealthKit/HKCorrelationType) is not a supported type for background delivery.

`frequency`

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`](/documentation/HealthKit/HKUpdateFrequency).

`completion`

A block that this method calls as soon as it enables background delivery. It passes the following parameters:

- `success`: A Boolean value. This parameter contains <doc://com.apple.documentation/documentation/Swift/true> if the system successfully enabled background delivery; otherwise, <doc://com.apple.documentation/documentation/Swift/false>.
- `error`: An error object. If an error occurred, this object contains information about the error; otherwise, it is `nil`.

## Discussion

Call this method to register your app for background updates.

> Important:
> For iOS 15 and watchOS 8 and later, you must enable the HealthKit Background Delivery by adding the <doc://com.apple.documentation/documentation/BundleResources/Entitlements/com.apple.developer.healthkit.background-delivery> entitlement to your app. If your app doesn’t have this entitlement, the ``doc://com.apple.healthkit/documentation/HealthKit/HKHealthStore/enableBackgroundDelivery(for:frequency:withCompletion:)`` method fails with an ``doc://com.apple.healthkit/documentation/HealthKit/HKError/Code/errorAuthorizationDenied`` error.

HealthKit wakes your app whenever a process saves or deletes samples of the specified type. The system wakes your app at most once per time period defined by the specified frequency. Some sample types have a maximum frequency of [`HKUpdateFrequency.hourly`](/documentation/HealthKit/HKUpdateFrequency/hourly). The system enforces this frequency  transparently.

For example, on iOS, [`stepCount`](/documentation/HealthKit/HKQuantityTypeIdentifier/stepCount) samples have an hourly maximum frequency.

In watchOS, most data types have an hourly maximum frequency; however, the following data types can receive updates at [`HKUpdateFrequency.immediate`](/documentation/HealthKit/HKUpdateFrequency/immediate):

- [`highHeartRateEvent`](/documentation/HealthKit/HKCategoryTypeIdentifier/highHeartRateEvent)
- [`lowHeartRateEvent`](/documentation/HealthKit/HKCategoryTypeIdentifier/lowHeartRateEvent)
- [`irregularHeartRhythmEvent`](/documentation/HealthKit/HKCategoryTypeIdentifier/irregularHeartRhythmEvent)
- [`environmentalAudioExposureEvent`](/documentation/HealthKit/HKCategoryTypeIdentifier/environmentalAudioExposureEvent)
- [`headphoneAudioExposureEvent`](/documentation/HealthKit/HKCategoryTypeIdentifier/headphoneAudioExposureEvent)
- [`lowCardioFitnessEvent`](/documentation/HealthKit/HKCategoryTypeIdentifier/lowCardioFitnessEvent)
- [`numberOfTimesFallen`](/documentation/HealthKit/HKQuantityTypeIdentifier/numberOfTimesFallen)
- [`vo2Max`](/documentation/HealthKit/HKQuantityTypeIdentifier/vo2Max)
- [`handwashingEvent`](/documentation/HealthKit/HKCategoryTypeIdentifier/handwashingEvent)
- [`toothbrushingEvent`](/documentation/HealthKit/HKCategoryTypeIdentifier/toothbrushingEvent)

Also, in watchOS, the background updates share a budget with <doc://com.apple.documentation/documentation/WatchKit/WKApplicationRefreshBackgroundTask> tasks. Your app can receive four updates (or background app refresh tasks) an hour, as long as it has a complication on the active watch face.

> Important:
> Background server queries aren’t supported on the Simulator. Be sure to test your background queries on a device.

### Receive Background Updates

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 <doc://com.apple.documentation/documentation/UIKit/UIApplicationDelegate/application(_:didFinishLaunchingWithOptions:)> method. By setting up the queries in <doc://com.apple.documentation/documentation/UIKit/UIApplicationDelegate/application(_:didFinishLaunchingWithOptions:)>, you ensure that you’ve instantiated your queries, and they’re 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 your app successfully received the background delivery. If you don’t call the update’s completion handler, HealthKit continues to attempt to launch your app using a backoff algorithm to increase the delay between attempts. If your app fails to respond three times, HealthKit assumes your app can’t receive data and stops sending background updates.

For more information on the background delivery completion handler, see [`HKObserverQueryCompletionHandler`](/documentation/HealthKit/HKObserverQueryCompletionHandler).

## See Also

[`HKObserverQuery`](/documentation/HealthKit/HKObserverQuery)

A long-running query that monitors the HealthKit store and updates your app when the HealthKit store saves or deletes a matching sample.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)