What’s the expected frequency of HealthKit enableBackgroundDelivery: HKCategoryTypeIdentifier.sleepAnalysis

Hello,

I have enabled HealthKit background delivery for sleep analysis samples:

    private func setupSleepDataBackgroundDelivery() {
        if let sleepType = HKObjectType.categoryType(forIdentifier: HKCategoryTypeIdentifier.sleepAnalysis) {
            healthStore.enableBackgroundDelivery(for: sleepType, frequency: .immediate) { (success, error) in
                
            }
        }
    }

In general, this function works.

But I would love to know what the limitations / expected delivery delay for frequency: .immediate is.

The documentation is only very vague about this and specifies that some sample types such as steps are only delivered once per hour.

But how about sleep data? Is this expected to be delivered immediately once available on iPhone?

Thanks a lot for your help!

@Quappi,

I do not have an answer, however, because the type is a HKCategoryType and the frequency of the data being saved should be low, it would be reasonable to assume that .immediate would behave the way you expect--immediate when on device.

I seem to recall the behaviors of some of the quantity samples are these buckets as you have described:

  • immediate
  • 10-minute
  • hourly
  • daily
  • weekly

I don't remember if the 10-minute bit was knowledge from a WWDC lab, or trial and error experimentation with workout APIs. Ever notice how Apple Watch will ask you if you're working out roughly after 10 minutes of walking?...

HKQuantityTypes have an aggregation style property, there is no reason that health types couldn't have a property to represent the fastest allowed background update frequency.

FB18604790 - HealthKit: Create new API for developers to check the minimum allowed update frequency for background updates, or robust documentation per-sample type

#feedbackfriday

What’s the expected frequency of HealthKit enableBackgroundDelivery: HKCategoryTypeIdentifier.sleepAnalysis
 
 
Q