I am working on the health kit. Before iOS15 below code is working correctly I am getting vitals on an hourly basis but in this latest version, I am not getting any vitals event per hour.
I am facing an issue in iOS15 not getting any event in an hourly event. Can anyone help me out? As per apple documentation https://developer.apple.com/documentation/healthkit/hkhealthstore/1614175-enablebackgrounddelivery I have enabled the permission in XCode13 still I am facing this issue.
Here is my code. (Working code before iOS15)
private func startObservingStepCountChanges() {
let sampleType = HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)
let query: HKObserverQuery = HKObserverQuery(sampleType: sampleType!, predicate: nil, updateHandler: self.stepChangeHandler)
healthKitStore.execute(query)
healthKitStore.enableBackgroundDelivery(for: sampleType!, frequency: .hourly, withCompletion: {(succeeded: Bool, error: Error!) in
if succeeded{
print("Enabled background delivery of stepcount changes")
} else {
if let theError = error{
print("Failed to enable background delivery of stepcount changes. ")
print("Error = \(theError)")
}
}
} as (Bool, Error?) -> Void)
}
private func stepChangeHandler(query: HKObserverQuery!, completionHandler: HKObserverQueryCompletionHandler!, error: Error!) {
// Flag to check the background handler is working or not
print("Backgound Mode activated")
fireTestPush()
completionHandler()
}
Check if background app refresh is enabled for your app. If it is and you're still running into this issue, file a feedback assistant report to Apple with sample code and sysdiagnose.