Enables the background delivery of updates.
- iOS 8.0+
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
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
YESif the background delivery was successfully enabled; otherwise,
An error object. If an error occurred, this object contains information about the error; otherwise, it is set to
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: method. By setting up the queries in
application:, 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