Skip to content

Avoid cold-start HealthKit observer registration for denied background types - #356

Draft
robertherber with Copilot wants to merge 2 commits into
masterfrom
copilot/v14-fix-healthkit-permission-issue
Draft

Avoid cold-start HealthKit observer registration for denied background types#356
robertherber with Copilot wants to merge 2 commits into
masterfrom
copilot/v14-fix-healthkit-permission-issue

Conversation

Copilot AI commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

v14 introduced a cold-start regression where the native HealthKit sheet could flash briefly even when JS never called requestAuthorization. The behavior was isolated to the new background-delivery startup path added in v14, not to the existing read/query APIs.

  • Root cause

    • BackgroundDeliveryManager registered HKObserverQuery instances for all persisted background types during app launch.
    • That happened before confirming enableBackgroundDelivery succeeded for each type, so denied/unavailable types could still be observed on cold start.
  • Change

    • Gate observer registration on successful enableBackgroundDelivery(...).
    • Only start the HKObserverQuery after HealthKit accepts background delivery for that type.
    • Skip late async observer startup if teardown already ran.
  • Impact

    • Preserves the v14 background-delivery architecture for authorized types.
    • Avoids cold-start observer setup for types HealthKit refuses, which is the likely trigger for the permission-sheet flash.
  • Implementation sketch

    healthStore.enableBackgroundDelivery(for: sampleType, frequency: frequency) { success, error in
      if success {
        self.startObserverQuery(typeIdentifier: typeIdentifier, sampleType: sampleType)
      }
    }

@changeset-bot

changeset-bot Bot commented Jun 3, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a9b415c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI changed the title [WIP] Fix HealthKit native sheet appearance on cold start Avoid cold-start HealthKit observer registration for denied background types Jun 3, 2026
Copilot AI requested a review from robertherber June 3, 2026 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v14: HealthKit native sheet appears briefly on cold start (regression vs v13)

2 participants