HealthKit event triggers each subscription

I'm trying to observe .irregularHeartRhythmEvent using HKObserverQuery.

Code, I'm using to subscribe to this event:

Code Block
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?

Have you found any resolution on this?

In the update handler of the HKObserverQuery you should create another HKSampleQuery according to the sampleType. This SampleQuery will return a samples collection and if the count of it is > 0, you have actual events.

HealthKit event triggers each subscription
 
 
Q