3

在 HealthKit 中,您创建一个 HKObserverQuery,执行它,然后启用BackgroundDeliveryForType。

let backgroundQuery:HKObserverQuery = HKObserverQuery(sampleType: quantityType, predicate: nil) { (query, complete, error) -> Void in
}
self.healthKitStore.executeQuery(backgroundQuery)

self.healthKitStore.enableBackgroundDeliveryForType(
        quantityType,
        frequency: .Immediate,
        withCompletion: { (success, error) -> Void in
            if !success {
                println(error)
            }
    })

我想知道如果我调用 disableBackgroundDeliveryForType 它只会禁用注册的 HKObserverQuery 还是会删除它?

4

1 回答 1

5

Disabling background delivery won't stop the observer query. It only prevents your app from being resumed in the background to be informed about new samples. When your app is in the foreground, your observer query's updateHandler will continue to execute when there is new data. You must call HKHealthStore.stopQuery(backgroundQuery) to stop it.

于 2015-05-31T21:46:46.363 回答