Monitor heart rate
The base HealthBridge provider observes heart-rate data exposed through HealthKit, Health Connect, or the editor mock. Platform synchronization can be delayed, so this path does not guarantee live timing.
Subscribe and start
Section titled “Subscribe and start”using HealthBridge;using HealthBridge.Data;using UnityEngine;
private void OnEnable(){ HealthBridgeEvents.OnHeartRateUpdated += HandleHeartRate;}
private void OnDisable(){ HealthBridgeEvents.OnHeartRateUpdated -= HandleHeartRate;}
private void HandleHeartRate(HeartRateSample sample){ double beatsPerMinute = sample.BeatsPerMinute; // Update transient gameplay or UI state.}
public async void StartMonitoring(){ IHealthProvider provider = HealthBridgeService.Provider; if (provider == null || !provider.Supports(HealthCapability.HeartRateMonitoring)) return;
bool started = await provider.StartHeartRateMonitoringAsync();}
public void StopMonitoring(){ HealthBridgeService.Provider?.StopHeartRateMonitoring();}Check provider support before showing monitoring controls.
Design for delayed data
Section titled “Design for delayed data”- Show the sample timestamp, not just BPM.
- Mark old values as stale.
- Handle long periods without a sample.
- Stop monitoring when the owning feature closes.
- Keep the product usable when heart rate is unavailable.
Protect heart-rate data
Section titled “Protect heart-rate data”Do not send BPM, timestamps, source labels, or raw callbacks to analytics, crash reports, general logs, or support tickets.
Verify
Section titled “Verify”The editor provider proves event and UI logic. Physical-device validation is still required for permissions, synchronization, backgrounding, and lifecycle recovery.
