What is the correct way to use background delivery in iOS 8 HealthKit?
The following is my code to enable HealthKit background delivery.
- (void)observeSleepData {
HKCategoryType *sleepType = [HKCategoryType categoryTypeForIdentifier:HKCategoryTypeIdentifierSleepAnalysis];
[self.healthStore enableBackgroundDeliveryForType:sleepType frequency:HKUpdateFrequencyImmediate withCompletion:^(BOOL success, NSError *error) {
if (success) {
}
}];
HKObserverQuery *query = [[HKObserverQuery alloc] initWithSampleType:sleepType predicate:nil updateHandler:^(HKObserverQuery *query, HKObserverQueryCompletionHandler completionHandler, NSError *error) {
NSLog(@"sleep data updated");
}];
[self.healthStore executeQuery:query];
}
Do I need to configure extra things to make this work other than enabling HealthKit capability? Does HKObserverQuery
respond to manual input in iOS8 native Health app?