Post

Replies

Boosts

Views

Activity

Reply to HKObserverQuery stops delivering updates in background on watchOS 26
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
Oct ’25
Reply to HKObserverQuery stops delivering updates in background on watchOS 26
Hi Ziqiao, @DTS Engineer I noticed that the feedback [FB20344425] status has been updated to “Investigation complete – Works as currently designed.” Could you please confirm whether this means that the current behavior—where HKObserverQuery with enableBackgroundDelivery initially works but permanently stops pushing health data after one day—is expected under the current system design? If this is indeed the intended behavior, are there any recommended approaches to ensure continuous or more reliable background data delivery for health-related apps on watchOS 26? Understanding the best practices for this scenario would be very helpful. Thank you very much for your time and assistance! Best regards, KeyCheung
Oct ’25
Reply to HKObserverQuery stops delivering updates in background on watchOS 26
Sorry, I missed part of the code. In fact, the error scenario also has a callback. I just sent a local notification and then immediately called completionHandler(). 【guard let heartType = HKObjectType.quantityType(forIdentifier: .heartRate) else { return } let query = HKObserverQuery(sampleType: heartType, predicate: nil) { query, completionHandler, error in if let error = error { logEvent("Observer 错误:\(error.localizedDescription)") completionHandler() return } logEvent("【心率有变化了") MyNotificationManager.shared.sendNotification() // 发了一个本地通知 completionHandler() } healthStore.execute(query) healthStore.enableBackgroundDelivery(for: heartType, frequency: .hourly) { success, error in if success { logEvent("已启用后台心率监听") } else { logEvent("后台监听心率失败:\(error?.localizedDescription ?? "未知错误")") } } 】
Sep ’25
Reply to HKObserverQuery stops delivering updates in background on watchOS 26
Sorry, @HealthyPotter I missed part of the code earlier. In fact, the error scenario also has a callback. let query = HKObserverQuery(sampleType: heartType, predicate: nil) { query, completionHandler, error in if let error = error { logEvent("Observer 错误:\(error.localizedDescription)") completionHandler() return } logEvent("【心率有变化了") MyNotificationManager.shared.sendNotification() // 发了一个本地通知 completionHandler() } healthStore.execute(query) healthStore.enableBackgroundDelivery(for: heartType, frequency: .hourly) { success, error in if success { logEvent("已启用后台心率监听") } else { logEvent("后台监听心率失败:\(error?.localizedDescription ?? "未知错误")") } } 】
Sep ’25