Skip to content

Conversation

@keima
Copy link

@keima keima commented Dec 5, 2025

Hello,

This pull request fixes an issue where calling queryCorrelationSamples() for a given correlation type and date range could fail with the following HealthKit error when there were no matching samples in the specified period:

[Error: Error Domain=com.apple.healthkit Code=3 "The types argument may not be empty" UserInfo={NSLocalizedDescription=The types argument may not be empty}]

Repro case (React Native):

const result = await HealthKit.queryCorrelationSamples(
  'HKCorrelationTypeIdentifierBloodPressure',
  startDate,
  endDate
);

From my investigation (confirmed via Xcode), this error occurs when HealthKit attempts to execute the correlation query and there are effectively no types/objects to resolve for the given time window. Instead of returning an empty array, the native side surfaced this as an error.

When no items registered via HealthKit:

When some (four) items registered:

This PR adjusts the implementation of queryCorrelationSamples so that:

  • In addition to when the correlations received from HealthKit are nil (null), I also made it so that it returns an empty array when an empty array is received.
  • This change prevents errors that occur when an empty array is passed to store.preferredUnits.

As a result, consumers can safely call queryCorrelationSamples() without needing to special‑case this HealthKit error and can treat “no data” as an empty list.

@changeset-bot
Copy link

changeset-bot bot commented Dec 5, 2025

🦋 Changeset detected

Latest commit: 6678bcb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@kingstinct/react-native-healthkit Patch

Not sure what this means? Click here to learn what changesets are.

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 5, 2025

Open in StackBlitz

npm i https://pkg.pr.new/kingstinct/react-native-healthkit/@kingstinct/react-native-healthkit@275

commit: 6678bcb

@keima
Copy link
Author

keima commented Dec 5, 2025

Updated PR description (add Xcode debugging image, rewrite implementation points)

@robertherber robertherber merged commit 2041b69 into kingstinct:master Dec 7, 2025
8 checks passed
@robertherber
Copy link
Member

Thanks @keima!

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.

3 participants