Hi, Ziqiao
Thanks for the clarification.
We’ve double-checked our implementation, and completionHandler() is indeed called in every branch, including when an error occurs.
Here’s the exact code we’re using:
if let error = error {
logEvent("❌ Observer 错误:\(error.localizedDescription)")
completionHandler()
return
}
logEvent("【💓】有变化了,准备Check")
self.dataCheck(source: "heartRate") {
logEvent("Check 结束,回调")
completionHandler()
}
}
self.healthStore.execute(query)
// 启用后台 delivery
self.healthStore.enableBackgroundDelivery(for: heartType, frequency: .immediate) { success, error in
logEvent(success ? "✅ 已启用后台监听_\(heartType)" : "❌ 启用_\(heartType)失败:\(error?.localizedDescription ?? "未知")")
}
Even though completionHandler() is always invoked, background delivery still stops after some time (usually within 2–3 days). Restarting the watch temporarily restores updates, but they eventually stop again.
We’ve tested this on:
Xcode 16.0 (26.0.1 / 17A400)
Devices & watch OS
Apple Watch Series 8 / watchOS 26.1(23S5002i)
Apple Watch Series 10 / watchOS 26.1(23S5017d)
If possible, could you help confirm whether our current implementation aligns with the recommended usage for HKObserverQuery background delivery?
Best
KeyCheung