Post not yet marked as solved
Post marked as unsolved with 1 replies, 567 views
I'm trying to observe .irregularHeartRhythmEvent using HKObserverQuery.
Code, I'm using to subscribe to this event:
private func subscribeForAbnormals() {
let abnormals = HKCategoryType.categoryType(forIdentifier: .irregularHeartRhythmEvent)!
healthStore.enableBackgroundDelivery(
for: abnormals,
frequency: HKUpdateFrequency.immediate
) { isSuccess, error in
let subscriptionStatus = isSuccess ? "OK ✅" : "FAILED ❌"
print("Irregular hearbeat subscription status: \(subscriptionStatus)")
if let error = error {
print(error.localizedDescription)
}
}
let query = HKObserverQuery(
sampleType: abnormals,
predicate: nil
) { [weak self] _, completionHandler, _ in
print("Irregular hearbeat detected")
completionHandler()
}
healthStore.execute(query)
}
Each time I call this function, I see output in my console:
Irregular hearbeat subscription status: OK ✅
Irregular hearbeat detected According to HealthApp, I have no cases of Irregular Hearth Rhythm.
Also, I havn't any options how to detect if triggered event is fake or not.
Absolutely same situation with .lowHeartRateEvent and .highHeartRateEvent
My app has all allowed accesses to HealthKit.
How can I actually subscribe for such kind of events to track this and notify user?